用PHP通过AR生成缩略图
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用PHP通过AR生成缩略图相关的知识,希望对你有一定的参考价值。
* Creates thumbnail from image* thumbnail dimensions can be set as parameters
* accepts JPG, JPEG, GIF, PNG
* preserves transparency for GIF and PNG on thumbnails
* call function like this: createthumb(images/original.jpg, thumbs/thumb.jpg, 80, 80);
/** * Function that creates thumbnail from image * Original author: Christian Heilmann * Fixed and extended: Ales Rebec * * @param $name Original filename (fullpath to image) * @param $filename Filename of the resized image (fullpath to thumbnail that will be created) * @param $new_w width of resized image in px (ex. 80 or 100) * @param $new_h height of resized image in px */ public function createthumb($name,$filename,$new_w,$new_h) { $type = 0; $mime = $size['mime']; //get image mime type (ex. "image/jpeg" or "image/gif") if (preg_match("/jpg|jpeg/i",$system[sizeof($system)-1])) {$type=1; $src_img=imagecreatefromjpeg($name);} if ($old_x > $old_y) //calculate thumnails dimenstions and preserve aspect ratio { $thumb_w=$new_w; $thumb_h=$old_y*($new_h/$old_x); } if ($old_x < $old_y) { $thumb_w=$old_x*($new_w/$old_y); $thumb_h=$new_h; } if ($old_x == $old_y) { $thumb_w=$new_w; $thumb_h=$new_h; } if($type > 1) $this->setTransparency($dst_img, $src_img); //if GIF or PNG -> set tranparency }
以上是关于用PHP通过AR生成缩略图的主要内容,如果未能解决你的问题,请参考以下文章