首页 > 后端开发 > php教程 > php上传图片生成缩略图

php上传图片生成缩略图

WBOY
发布: 2016-07-25 08:46:09
原创
1293 人浏览过
  1. function createThumbnail($imageDirectory, $imageName, $thumbDirectory, $thumbWidth, $quality){
  2. $details = getimagesize("$imageDirectory/$imageName") or die('Please only upload images.');
  3. $type = preg_replace('@^.+(? eval('$srcImg = imagecreatefrom'.$type.'("$imageDirectory/$imageName");');
  4. $thumbHeight = $details[1] * ($thumbWidth / $details[0]);
  5. $thumbImg = imagecreatetruecolor($thumbWidth, $thumbHeight);
  6. imagecopyresampled($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight,
  7. $details[0], $details[1]);
  8. eval('image'.$type.'($thumbImg, "$thumbDirectory/$imageName"'.
  9. (($type=='jpeg')?', $quality':'').');');
  10. imagedestroy($srcImg);
  11. imagedestroy($thumbImg);
  12. }
  13. foreach ($_FILES["pictures"]["error"] as $key => $error) {
  14. if ($error == UPLOAD_ERR_OK) {
  15. $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
  16. $name = $_FILES["pictures"]["name"][$key];
  17. move_uploaded_file($tmp_name, "data/$name");
  18. createThumbnail("/location/of/main/image", $name, "/location/to/store/thumb", 120, 80);
  19. //120 = thumb width :: 80 = thumb quality (1-100)
  20. }
  21. }
  22. ?>
复制代码

上传图片, php


来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板