Running a batch with imagemagick - imagemagick

I need to save a bunch (several thousand) of images with imagemagick.
I'm totally new to it, and its documentation seems totally opaque and totally labyrinth. Where's the quickstart guide?
Looking at it, I think I want to use mogrify.
so I cd to my program files directory where I installed imagemagick.
I run mogrify -format png *.png as I see in various examples.
It says:
mogrify: unable to open image `fgimg\': No such file or directory # blob.c/OpenB
lob/2489.
mogrify: unable to open file `fgimg\' # png.c/ReadPNGImage/2865.
How do I instruct it to run on all images in the subdirectory \fgimg?
Thanks a lot!

The problem here is that you're hitting the limit of how much you can put on a command line. You need to split it into chunks that will fit. This should work better:
find -name '*.png' -print0 | xargs -0 -r mogrify -format png
The -print0 and -0 are used to handle spaces in filenames, and the -r means don't run mogrify if there's nothing to do.

Related

Batch-converting of INTA images

I have a large number of images in the INTA format, an old SGI standard. INTA is a grayscale image with an alpha channel. All of these need to be converted to TGA files. The problem is that neither ImageMagick nor PIL/Pillow seem to be able to parse them correctly. ImageMagick can read and export them but doesn't seem to understand the alpha channel, and PIL fails to open them, with the error ValueError: Unsupported SGI image mode. The one thing that I've found that reads them successfully is GIMP:
An ideal solution would be one that is easy to invoke from a script.
For reference, here is one of the images in question (the same one seen in the screenshot): https://www.dropbox.com/s/8hoppdgtuqxsy26/girder01.inta?dl=0
It seems GDAL is able to read your image and I converted it to a greyscale+alpha PNG using:
gdal_convert YOURIMAGE.sgi result.png
You can easily get to TGA from there.
I am assuming the batching is not an issue, but it would look something like this in bash:
mkdir -p OUTPUT
for f in *.inta ; do
gdal_translate "$f" OUTPUT/"$f"
done
I had all sorts of trouble installing GDAL on macOS so I just used docker like this:
docker run --rm -v /Users:/Users osgeo/gdal:alpine-normal-latest gdal_translate /Users/mark/Downloads/image.sgi /Users/mark/Downloads/result.png

Mogrify command modify file names?

Im using mogrifiy command in Ubuntu server 20.04 to make a bulk resize, but i will like to know if the use of this command modify the name of the images. Theres my command
mogrify -resize 600x400 '*.jpg'
No, it doesn't. If you want the results in a new directory called RESULTS, you can do mkdir RESULTS then mogrify -path RESULTS -resize 600x400 *.jpg if that's what you mean. – Mark Setchell

How to use imagemagick to bulk crop images' whitespace just like the "trim()" of a string?

I have many PNGs uploaded by users.
However, they have white spaces around, which should be removed.
For instance:
An image like this:
Should be cropped to an image like this:
What should I do if I want to do this to all files matching *_spec.PNG files in a directory and all its subdirectories?
Example files:
Folder
|
Subfolder1 - file1_spec.png
- file2_spec.png
- file3.png
|
Subfolder2 - filea.png
- fileb1_spec.png
I need to do this to these files:
Subfolder1/file1_spec.png
Subfolder1/file2_spec.png
Subfolder2/fileb1_spec.png
Update:
OS: MacOSX Mojave 10.14.6
Imagemagick version: 7.0.10-22 Q16 x86_64 2020-06-27
I would make a COPY of your files in a spare directory before you do anything. Then go to the top directory and run:
find . -iname "*_spec.png" -exec mogrify -trim {} \;
Note that there are more efficient ways of doing this, but they are less readable and only really worth it if you have tens of thousands of files, or more. For anyone who's interested, that means using GNU Parallel and/or trimming more than one file per invocation of ImageMagick to better amortize the process creation time over multiple files.

How to batch convert JPG image gallery to BPG image format

How to convert whole image gallery or family album from JPG to BPG image format?
I'm looking for some batch conversion tool, application or script on Windows platform.
Input directory must be processed recursively and image quality should be preserved.
Linux command line fragment I use for this task, with current directory being gallery of '*.JPG' files, without subdirectories.
parallel -i sh -c 'convert -quality 100 {} -scale "1280x1000>" {}.png && bpgenc -q 30 {}.png -o {}.bpg && rm -f {}.png' -- *.JPG
You may adjust (or remove) resizing and change -q 30 to lower value for more quality.
It depends on ImageMagick and bpgenc.
To run in on Windows, you probably will need Cygwin.
Look at
http://www.romeolight.com/products/bpgconv/
for nice Windows converter.
2 things to mention: Currently there is options menu in top right of window. And all BPG pictures are saved into folder on your desktop called bpg_encoded.
Martin

How to flop multiple images using imagemagik?

I tried to flip horizontally the images in a specific folder using ImageMagik. But the mogrify -flop *jpg is changing all the images in their mirror images. I want to keep the initial images and for the flopped ones I want to rename them as *_flop.jpg. I am stuck: How to do it?
Assuming you are on Linux or OSX, like this:
#!/bin/bash
for f in *.jpg; do
new="${f%%.jpg}_flop.jpg"
echo convert "$f" -flop "$new"
done
At the moment, it does nothing, it just tells you what it would do. If you like what it shows, just remove the word echo and run it again.
Save the code above as flopper, and then go to Terminal and type this:
chmod +x flopper # Just do this one time to make the script executable (runnable)
./flopper # Actually run it
Update:
For newer versions of ImageMagick (version 7 onwards) you do not need to write:
convert -flop
Instead you need to write:
magick -flop
So your script essentially becomes:
#!/bin/bash/
for file in *.jpg
do
magick $file -flop ${file%%.jpg}_flop.jpg
done
Note: This works when your filenames don't have spaces or newlines in them.

Resources