mogrify batch @textfile.txt not working

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
surf_uk
Posts: 6
Joined: 2011-01-27T10:24:12-07:00
Authentication code: 8675308

mogrify batch @textfile.txt not working

Post by surf_uk »

I have been using the following command successfully in the past but now it has stopped working:

Code: Select all

mogrify -crop 300x300+0+0 -gravity Center @picsToConvert.txt
The picsToConvert.txt file contains:

Code: Select all

/media/media/0004_x264m_libschro/results/original/crop/00100.png
/media/media/0004_x264m_libschro/results/original/crop/00200.png
The error is:

Code: Select all

mogrify: unrecognized gravity type `magick' @ error/mogrify.c/MogrifyImageCommand/5057.
The version is from Ubuntu repository:

Code: Select all

Version: ImageMagick 6.6.2-6 2010-12-02 Q16 http://www.imagemagick.org
It's as though the @ symbol is being read as part of the gravity option, or whatever option preceeds the @.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: mogrify batch @textfile.txt not working

Post by fmw42 »

Mogrify works on directories and as far as I know does not work from a text file list of images.

Convert will work with a text file as input. The output image could be some multiframe format or separate images.

This work:

convert logo.png zelda3.png lena.png -gravity center -crop 100x100+0+0 +repage tmp.tiff (gives a multiframe image)
or
convert logo.png zelda3.png lena.png -gravity center -crop 100x100+0+0 +repage tmp_%d.png (gives multiple images)

And if I put all 3 image names in a text file, then this works.

convert @tmp.txt -gravity center -crop 100x100+0+0 +repage tmp2_%d.png



Also you could write a script that will read the images from the text file and loop over a convert to crop the image and write an appropriate output for each image.
surf_uk
Posts: 6
Joined: 2011-01-27T10:24:12-07:00
Authentication code: 8675308

Re: mogrify batch @textfile.txt not working

Post by surf_uk »

Well this used to work. As I understood it, mogrify modifies an image (i.e. crop me.jpg) whereas convert requires both an input and output image file (i.e. convert me.jpg to me.png). Is it possible to do this with convert without generating another image file which I would have to find and remove?

Because the images I need to crop are in arbitrary locations I used the text file with image paths to achieve batch job processing. If I swap the arguments around to:

Code: Select all

mogrify @picsToConvert.txt -crop 300x300+0+0 -gravity Center 
This works and I can see that mogrify is touching each image and the Gnome folder thumbnail refreshes but it does not crop anything. Its as if the commands need to preceed the files.

Any ideas?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: mogrify batch @textfile.txt not working

Post by magick »

Try the -crop option right after the 'mogrify' keyword and before the file path filename.
surf_uk
Posts: 6
Joined: 2011-01-27T10:24:12-07:00
Authentication code: 8675308

Re: mogrify batch @textfile.txt not working

Post by surf_uk »

I'm afraid this doesn't work either...

Code: Select all

ross@ross-encoder:/media/media/240subset/test$ mogrify -crop 30x30+0+0 @pics.txt -gravity Center
mogrify: invalid argument for option `magick': -crop @ error/mogrify.c/MogrifyImageCommand/4546.
ross@ross-encoder:/media/media/240subset/test$ 
ross@ross-encoder:/media/media/240subset/test$ 
ross@ross-encoder:/media/media/240subset/test$ mogrify -crop @pics.txt 30x30+0+0 -gravity Center
mogrify: unable to open image `30x30+0+0':  @ error/blob.c/OpenBlob/2498.
mogrify: no decode delegate for this image format `30x30+0+0' @ error/constitute.c/ReadImage/532.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: mogrify batch @textfile.txt not working

Post by fmw42 »

try putting the list of images last in the mogrify command
surf_uk
Posts: 6
Joined: 2011-01-27T10:24:12-07:00
Authentication code: 8675308

Re: mogrify batch @textfile.txt not working

Post by surf_uk »

Isn't that what I tried in my original post?

Edit... sorry yes this works:

Code: Select all

ross@ross-encoder:/media/media/240subset/test$ mogrify -crop 30x30+0+0 -gravity Center 00001.png 00002.png 
ross@ross-encoder:/media/media/240subset/test$ 
But how could put the list of images in at the end, from a text file?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: mogrify batch @textfile.txt not working

Post by magick »

We're using ImageMagick 6.6.7-3. This command worked as expected without complaint;
  • mogrify -crop 100x100+100+100 -gravity center @paths.txt
surf_uk
Posts: 6
Joined: 2011-01-27T10:24:12-07:00
Authentication code: 8675308

Re: mogrify batch @textfile.txt not working

Post by surf_uk »

Maybe it's a bug which has been fixed. Can you ask Canonical/Ubuntu to update their version ?

I have found a work around using this script:

http://bash.cyberciti.biz/file-manageme ... e-by-line/

and adding this line to the processLine() function:

Code: Select all

  echo "mogrify -crop 300x300+0+0 -gravity Center $line"
  mogrify -crop 300x300+0+0 -gravity Center $line
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: mogrify batch @textfile.txt not working

Post by anthony »

For other methods of doing a file list see
http://www.imagemagick.org/Usage/basics/#mogrify_not

xargs is good method.

cat list_of_files.txt | xargs -i mogrify .... '{}'

parallel is a xargs equivelent that will use multiple cores to process files in parellel though as IM is already multi-threaded that may not always be a good thing.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
surf_uk
Posts: 6
Joined: 2011-01-27T10:24:12-07:00
Authentication code: 8675308

Re: mogrify batch @textfile.txt not working

Post by surf_uk »

Thanks that's a very elegant batch process method and a brilliant resource link!
Post Reply