简体   繁体   中英

Deleting the old image after it was converted to png with imagepng

I found this function on stackoverflow which is :

imagepng(imagecreatefromstring(file_get_contents($filename)), "output.png");

I thought it would fit my needs since it renames/change path/convert to png at the same time, but it doesn't exactly convert the image, it creates a "png copy". I would like the old jpg/gif/jped/png image to be erased aswell.

Is there a way I can add that to this "one-line converting function" ?

Thanks a lot !

You're doing a lot in one line:

Read the file:

$file = file_get_contents($filename);

create image object from the contents:

$image = imagecreatefromstring($file);

create png from image object

imagepng($image, "output.png");

You should check these steps to find where the issue is.

My guess? You're missing write permissions on the folder you're writing to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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