Q
PHP临时缩略图
0
A
回答
1
您可以使用这样的功能。
参考http://tutorialfeed.net/development/scale-an-image-using-php
function create_thumb($imgSrc, $thumbnail_width, $thumbnail_height, $dest_src, $ext)
{
//getting the image dimensions
list($width_orig, $height_orig) = getimagesize($imgSrc);
// Check if the images is a gif
if($ext == 'gif')
{
$myImage = imagecreatefromgif($imgSrc);
}
// Check if the image is a png
elseif($ext == 'png')
{
$myImage = imagecreatefrompng($imgSrc);
}
// Otherwise, file is jpeg
else
{
$myImage = imagecreatefromjpeg($imgSrc);
}
// Find the original ratio
$ratio_orig = $width_orig/$height_orig;
// Check whether to scale initially by height or by width
if($thumbnail_width/$thumbnail_height > $ratio_orig)
{
$new_height = $thumbnail_width/$ratio_orig;
$new_width = $thumbnail_width;
}
else
{
$new_width = $thumbnail_height*$ratio_orig;
$new_height = $thumbnail_height;
}
$x_mid = $new_width/2; //horizontal middle
$y_mid = $new_height/2; //vertical middle
$process = imagecreatetruecolor(round($new_width), round($new_height));
// Scale the image down and the reduce the other axis to create the thumbnail
imagecopyresampled($process, $myImage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
$thumb = imagecreatetruecolor($thumbnail_width, $thumbnail_height);
imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumbnail_width/2)), ($y_mid-($thumbnail_height/2)), $thumbnail_width, $thumbnail_height, $thumbnail_width, $thumbnail_height);
// Depending on the file extension, save the file
if($ext == 'gif')
{
imagegif($thumb, $dest_src);
}
elseif($ext == 'png')
{
imagepng($thumb, $dest_src);
}
else
{
imagejpeg($thumb, $dest_src, 100);
}
// Remove rubbish file data
imagedestroy($process);
imagedestroy($myImage);
// Return thumb (success/fail)
return $thumb;
}
+0
我最终使用了它,因为它适用于所有文件类型,谢谢 – user1083382 2012-02-17 11:27:05
0
可以使用ImageWorkshop的resizeInPourcent()方法(使用库GD库):http://phpimageworkshop.com/doc/17/resizing.html
例:
<?php
$myImage->resizeInPourcent(50, 50); // Resize to get 50% width and height
相关问题
- 1. 在即时缩略图PHP
- 2. PHP缩略图
- 3. PHP缩略图图像
- 4. 分页缩略图PHP
- 5. ng-file-upload v12.0.1 - 生成缩略图时显示临时的“加载”图标
- 6. 即时创建缩略图
- 7. YouTube v3中的缩略图缩略图
- 8. PHP图像缩略图性能?
- 9. PHP,操纵图像和缩略图?
- 10. PHP图片上传压缩临时文件大小
- 11. 缩略图
- 12. DropBox缩略图
- 13. BxSlider缩略图
- 14. 缩略图asp.net
- 15. Django缩略图
- 16. FLV缩略图
- 17. imagemagick缩略图
- 18. 图像缩略图
- 19. 在php/Javascript/jqueryurl中检索URL的缩略图标题,描述和缩略图
- 20. php-ffmpeg太慢 - 生成缩略图?
- 21. PHP画廊,缩略图列表
- 22. php缩略图放大点击
- 23. 用Symfony或PHP创建缩略图
- 24. 使用php显示缩略图pdf
- 25. Div内php。网上商店缩略图
- 26. 如何用php制作缩略图
- 27. pdf缩略图imagemagick php不工作
- 28. php imgcopyresampled - 改变缩略图的宽度
- 29. ffmpeg-php创建视频缩略图
- 30. PDF缩略图shell命令问题 - PHP
imagecopyresampled:HTTP:/ /php.net/manual/en/function.imagecopyresampled.php – dbrumann 2012-02-17 10:33:52
查看PHP GD库。 – deed02392 2012-02-17 10:33:59
@mahok完美谢谢你! – user1083382 2012-02-17 11:02:00