Is there any function for create thumbnail image in php?
Is there any function for cr开发者_Go百科eate thumbnail image in php ?
There's no single function that will create the thumbnail for you, but there are several functions that are part of the GD library, like imagecreatetruecolor
and imagecopyresampled
. The best thing you could do is start with a tutorial, Google knows best here:
http://www.google.co.uk/search?q=gd+php+thumbnail
you have a GD library function for image creation...pls follow the URL
http://php.net/manual/en/book.image.php
You can use the following code to generate the image thumbnail without changing the aspect ratio of the original image. And here $img is the path of image where original image is stored.
$sourceAppImgPath = $this->images->absPath($img);
$file_dimensions = getimagesize($sourceAppImgPath);
$ImageType = strtolower($file_dimensions['mime']);
switch(strtolower($ImageType))
{
case 'image/png':
$image = imagecreatefrompng($sourceAppImgPath);
break;
case 'image/gif':
$image = imagecreatefromgif($sourceAppImgPath);
break;
case 'image/jpeg':
$image = imagecreatefromjpeg($sourceAppImgPath);
break;
default:
return false; //output error
}
$origWidth = imagesx($image);
$origHeight = imagesy($image);
$maxWidth = 300;
$maxHeight =300;
if ($maxWidth == 0)
$maxWidth = $origWidth;
if ($maxHeight == 0)
$maxHeight = $origHeight;
$widthRatio = $maxWidth / $origWidth;
$heightRatio = $maxHeight / $origHeight;
$ratio = min($widthRatio, $heightRatio);
$thumb_width = (int)$origWidth * $ratio;
$thumb_height = (int)$origHeight * $ratio;
精彩评论