PHP 是最近的热门语言,那么如果 php 要生成缩略图有什么办法
呢?其实 php 生成缩略图有两种方法,核心代码如下,更多消息请关
注应届毕业生网!
public function getImage(){
$basePath = base_path('public/');
$md5 = 'b8c3bf0b10a81c5b6a98c527868a0000';$sub1 =
substr($md5, 0, 1);$sub2 = substr($md5, 1, 2);
$subPath = sprintf("image/%s/%s/%s%s.jpg", $sub1, $sub2,
$md5, '300x300');$sourcePath = sprintf("image/%s/%s/%s.jpg",
$sub1, $sub2, $md5);// 截 成 100x80 的 ` 缩 略 图 //$image =
$this->getCropper($basePath.$sourcePath,$basePath.$subPath,
$this->getCrops($basePath.$sourcePath,$basePath.$subPath,
getCropper($source_path,$NewImagePath,
$target_height){$source_info
getimagesize($source_path);$source_width
$source_info[0];$source_height = $source_info[1];
$source_mime = $source_info['mime'];
$source_width;$target_ratio = $target_height / $target_width;//
源图过高 if ($source_ratio > $target_ratio)
{
$cropped_width = $source_width;
$cropped_height = $source_width * $target_ratio;$source_x