Rumah >pembangunan bahagian belakang >tutorial php >php上传图片生成缩略图

php上传图片生成缩略图

WBOY
WBOYasal
2016-07-25 08:46:091296semak imbas
  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


Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn