Delete image after processing

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
mcguinnessdr
Posts: 6
Joined: 2013-08-26T15:07:41-07:00
Authentication code: 6789

Delete image after processing

Post 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!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Delete image after processing

Post 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
Last edited by fmw42 on 2013-08-27T18:09:32-07:00, edited 1 time in total.
mcguinnessdr
Posts: 6
Joined: 2013-08-26T15:07:41-07:00
Authentication code: 6789

Re: Delete image after processing

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Delete image after processing

Post by fmw42 »

try an absolute path, though a relative one should work.

what version of IM and platform are you using?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Delete image after processing

Post 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.
snibgo's IM pages: im.snibgo.com
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Delete image after processing

Post 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".
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Delete image after processing

Post 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
mcguinnessdr
Posts: 6
Joined: 2013-08-26T15:07:41-07:00
Authentication code: 6789

Re: Delete image after processing

Post by mcguinnessdr »

Thanks for all the help, it's working perfectly now!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Delete image after processing

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply