php上传图片生成缩略图

WBOY
풀어 주다: 2016-07-25 08:46:09
원래의
1202명이 탐색했습니다.
  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으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!