简体   繁体   English

php图片大小调整并在上传时转换为jpg

[英]php image resize and convert to jpg on upload

How to resize an image and convert to .jpg on upload? 如何调整图片大小并在上传时转换为.jpg? Basically something like the post here 基本上像这里的帖子

How do I resize and convert an uploaded image to a PNG using GD 如何使用GD调整大小并将上传的图像转换为PNG

But i need to convert to JPG... 但是我需要转换为JPG ...

I tried imagejpeg() instead of imagepng() but it still saves it as png. 我尝试使用imagejpeg()而不是imagepng()但是它仍将其另存为png。

It that thread that you linked to, the accepted answer is converting to png like this: 您链接到的那个线程,可接受的答案将转换为png,如下所示:

imagepng($newImage, $destFile);

Your code would need to be only slightly different: 您的代码只需稍有不同:

imagejpg($newImage, $destFile);

See the PHP docs and this thread for further reference: 请参阅PHP文档该线程以获取更多参考:

有一个现成的类,您可以尝试-http: //wideimage.sourceforge.net/

您可以申请:

imagejpeg($this->image,$filename,$compression);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM