Page 1 of 1

Delete image after processing

Posted: 2013-08-27T16:25:56-07:00
by mcguinnessdr
Hello, I am converting a large amount of images and would like to have imagemagick delete the source image after it's converted. I've tried "+delete" and "-delete 0" and both cause imagemagick to crash. Here's the command I'm running:

Code: Select all

mogrify -background black -density 670 -format png *.svg
What do I need to add to accomplish this? Thank you for any help!

Re: Delete image after processing

Posted: 2013-08-27T16:39:13-07:00
by fmw42
The best thing would be to put the results in a new directory and then delete the old directory using rm -rf path2/olddirectory (on unix --- I am not sure what the equivalent is in Windows).

It is always better to put your mogrify results into a new directory in case of a problem, so you do not corrupt or overwrite them until you are satisfied it all worked well.

see -path argument in mogrify

http://www.imagemagick.org/Usage/basics/#mogrify

Re: Delete image after processing

Posted: 2013-08-27T16:46:45-07:00
by mcguinnessdr
The -path command doesn't seem to be working. I have a subfolder called "pngs" and I've tried "-path ../pngs", "-path ..\pngs", "-path /pngs", and "-path \pngs", but all of these give the "No such file or directory" error.

Re: Delete image after processing

Posted: 2013-08-27T17:10:57-07:00
by fmw42
try an absolute path, though a relative one should work.

what version of IM and platform are you using?

Re: Delete image after processing

Posted: 2013-08-27T17:26:28-07:00
by snibgo
"ephemeral:" works. Eg ...

Code: Select all

convert ephemeral:rose.jpg rose.png
... will read rose.jpg, write rose.png then delete the file rose.jpg.

Personally, I don't use it.

Re: Delete image after processing

Posted: 2013-08-27T17:31:47-07:00
by snibgo
If "pngs" is a subdirectory of where you are, the command is "-path pngs".

If it is a subdirectory of this directory's parent, use "-path ../pngs".

Re: Delete image after processing

Posted: 2013-08-27T18:03:23-07:00
by fmw42
snibgo wrote:"ephemeral:" works. Eg ...

Code: Select all

convert ephemeral:rose.jpg rose.png
... will read rose.jpg, write rose.png then delete the file rose.jpg.
Thanks, snibgo, for reminding me about that. I was surprised but it does work in mogrify. I just tried

mogrify -format png ephemeral:*.svg

which does replace all .svg files with .png versions. The .svg files are automatically removed.

Learned something new today! :-o :-D


see
http://www.imagemagick.org/Usage/files/#ephemeral

Re: Delete image after processing

Posted: 2013-08-27T18:56:49-07:00
by mcguinnessdr
Thanks for all the help, it's working perfectly now!

Re: Delete image after processing

Posted: 2013-09-29T23:47:05-07:00
by anthony
Be very careful with ephemeral. It will delete the file after it has been read into memory.
That is before the image is finished processing.

You probably want to ensure the image is fully processed and written out (with a vaild image) before deleteing the original image.

Ephemeral: is used more to inform a controling process that the reader has finished reading the image and can thus be left on its own. It is used for example with a "show:" delegate to launch "display" commands in the background. Once "display" has read then image, the main process can continue with what it is doing.

I have also used it to create slideshows where the next image is not determined in advance, or the next image is created while the old image being displayed. Using ephemeral on a symbolic link pointing to a image, is also useful as it will remove the symbolic link and not the image pointed to.

NOTE: There is currently no way to get "animate" or "display" to signal when it has finished an animation, or has actually put the image up for display. :-(

However you can have "convert" read a seperate "ephemeral:" image, to notify a controling script that it has reached a specific point in its image processing.

I have added some of these notes to IM examples, File Handling, Ephemeral
http://www.imagemagick.org/Usage/files/#ephemeral