当前位置:Gxlcms > PHP教程 > 图片上传并使用ImageMagick生成缩略图

图片上传并使用ImageMagick生成缩略图

时间:2021-07-01 10:21:17 帮助过:47人阅读

使用ImageMagick,您可以轻松,更快地创建缩略图,比使用PHP的容易得多。
  1. // Location to upload main image:
  2. $mainDir = $_SERVER['DOCUMENT_ROOT'].'/images/l/';
  3. // Location to create the thumb image:
  4. $smalDir = $_SERVER['DOCUMENT_ROOT'].'/images/s/';
  5. // Command to use:
  6. $command = '/usr/bin/convert';
  7. // Thumbnail width:
  8. $size = 210;
  9. // Make sure we have an image:
  10. if(isset($_POST['submit'])){
  11. if(getimagesize($_FILES['photo']['tmp_name'])){
  12. $name = $_FILES['photo']['name'];
  13. $uploadfile = $mainDir . $name;
  14. move_uploaded_file($_FILES['photo']['tmp_name'], $uploadfile);
  15. $lrgImg = $mainDir . $name;
  16. $smlImg = $smalDir . $name;
  17. $imageMagick = $command . " '". $lrgImg . "' -resize '$size' '" . $smlImg . "'";
  18. shell_exec($imageMagick);
  19. }
  20. header("Location: /test.php");
  21. exit;
  22. }else{
  23. ?>
  24. foreach(glob($smalDir.'*') as $img){
  25. echo ' ';
  26. }
  27. }
  28. ?>

图片上传, ImageMagick

人气教程排行