如何使用PHP-Image-Resizing脚本调整图像大小

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何使用PHP-Image-Resizing脚本调整图像大小相关的知识,希望对你有一定的参考价值。

  1. <?php
  2.  
  3. // This is the temporary file created by PHP
  4. $uploadedfile = $_FILES['uploadfile']['tmp_name'];
  5.  
  6. // Create an Image from it so we can do the resize
  7. $src = imagecreatefromjpeg($uploadedfile);
  8.  
  9. // Capture the original size of the uploaded image
  10. list($width,$height)=getimagesize($uploadedfile);
  11.  
  12. // For our purposes, I have resized the image to be
  13. // 600 pixels wide, and maintain the original aspect
  14. // ratio. This prevents the image from being "stretched"
  15. // or "squashed". If you prefer some max width other than
  16. // 600, simply change the $newwidth variable
  17. $newwidth=600;
  18. $newheight=($height/$width)*600;
  19. $tmp=imagecreatetruecolor($newwidth,$newheight);
  20.  
  21. // this line actually does the image resizing, copying from the original
  22. // image into the $tmp image
  23. imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
  24.  
  25. // now write the resized image to disk. I have assumed that you want the
  26. // resized, uploaded image file to reside in the ./images subdirectory.
  27. $filename = "images/". $_FILES['uploadfile']['name'];
  28. imagejpeg($tmp,$filename,100);
  29.  
  30. imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when the request
  31. // has completed.
  32. ?>

以上是关于如何使用PHP-Image-Resizing脚本调整图像大小的主要内容,如果未能解决你的问题,请参考以下文章

LUA脚本中的方法使用冒号和点,以及调用者使用冒号和点

Linux,Unix,MacOS等其中的Bash脚本判别调用者使用者的身份

如何检查调用者是不是设置了 PowerShell 可选参数

如何访问函数内调用者的命令行参数?

如何检查调用者是否设置了PowerShell可选参数

shell脚本调JAVA程序,获取JAVA程序返回值并echo输出