php上传图片生成缩略图

WBOY
Libérer: 2016-07-25 08:46:09
original
1202 Les gens l'ont consulté
  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


Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!