Hi,
Is it possible to delete an image with "convert" after resizing? The problem is that I try to delete an image using PHP function unlink() after using shell_exec("convert -resize ...") but sometimes image is still in progress so PHP can't delete an image and just ignore unlink() function. After several days I have a tons of images weren't deleted and I have to delete them manually.
Delete source image after resizing
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Delete source image after resizing
No, not as far as I know. You cannot delete the input image after resizing it with convert with IM. With mogrify you can write over the input image.
Re: Delete source image after resizing
Thats strange; I am currently working on a code that is modifying and deleting hundreds of images without a problem.
I use exec rather than shell_exec does that make a difference ?
I would have thought that once the image has been read into ImageMagick it could be deleted.
What about adding a sleep between the IM code and the unlink() http://php.net/manual/en/function.sleep.php
I use exec rather than shell_exec does that make a difference ?
I would have thought that once the image has been read into ImageMagick it could be deleted.
What about adding a sleep between the IM code and the unlink() http://php.net/manual/en/function.sleep.php
Re: Delete source image after resizing
It's not possible to use sleep() because the priority is to make an image than delete it.
system("convert -resize ...");
unlink("path/to/file");
Some files still can not be deleted with this code while IM is in progress.
The only option is to make a new script to delete these images using cron.
I also tried to use a system() function:I would have thought that once the image has been read into ImageMagick it could be deleted.
system("convert -resize ...");
unlink("path/to/file");
Some files still can not be deleted with this code while IM is in progress.
The only option is to make a new script to delete these images using cron.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Delete source image after resizing
Are you trying to delete the input or output. If the output, you can use temp files such as PNG: or JPG:
Re: Delete source image after resizing
I'm trying to delete the input file after the output file created.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Delete source image after resizing
Only way I can think to do it uses some unix:
convert zelda3b.jpg \( +clone -resize 50% -write zelda3b_small.jpg \) null: | rm zelda3b.jpg
you may be able to leave off the pipe to rm and use your PHP unlink to delete the input. Since the clone is made before the resize, then the input can be deleted at any time after the clone is made and before or while the resize. The clone will go away after the convert finishes.
However, might it be a problem with your server and a delay in updating the file list in the directory. Even though the image is created, the file list may not yet be finished updating, especially if you have many many images in the file list.
convert zelda3b.jpg \( +clone -resize 50% -write zelda3b_small.jpg \) null: | rm zelda3b.jpg
you may be able to leave off the pipe to rm and use your PHP unlink to delete the input. Since the clone is made before the resize, then the input can be deleted at any time after the clone is made and before or while the resize. The clone will go away after the convert finishes.
However, might it be a problem with your server and a delay in updating the file list in the directory. Even though the image is created, the file list may not yet be finished updating, especially if you have many many images in the file list.
Re: Delete source image after resizing
You can delete an image after its read with the ephemeral tag. Its not advertised because its destructive. Try this:
- -> convert logo: logo.jpg
-> convert ephemeral:logo.jpg logo.png
-> ls logo.jpg logo.png
ls: cannot access logo.jpg: No such file or directory
logo.png
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Delete source image after resizing
very interesting. i never noticed that before, but see http://www.imagemagick.org/Usage/files/#ephemeral