Using convert or mogrify to merge multiple PNG files into a single multi-page TIFF file - image

Say I have a folder foo with multiple PNG files. Is there a way to use convert or mogrify to merge the PNG files into a single TIFF file?
I have tried:
mogrify -format tiff -adjoin *.png
but I get unrecognized option -adjoin

Using Version: ImageMagick 6.6.1-5 2010-04-23 Q16, this works just fine:
convert *.png all.tiff

To merge them into a single file as an image sequence you can use the answer given by Matthias Osidio.
-append creates a single image where the images in the original set are stacked top-to-bottom.
mogrify -append *.png output.tiff

Related

crop and keep the names on multiples images on magick

I would like to crop multiple images files and keep the same name or add a "_2" at the end of the name.
any idea how to do it?
I tried this
magick *jpg -set filename:base "%[basename]" -fuzz 90% "%[filename:base]_2.jpg"
To just keep the same name use magick mogrify. This works exactly like magick or magick convert but overwrites the input file, so there is no output specification. It is quite simple to use on a set of files:
magick mogrify [parameters] file [file...]

Conversion of ENVI binary files to tiff

I have a challenge in converting a batch of ENVI binary files(BSQ) temperature data(gotten from SAFARI 2000 AVHRR-Derived LST) to geotiff files. How can i read them and convert it to geotiff?
An example of one such file is 'afn_011-011_96.n14-LST_UL'
You would need to provide a proper sample dataset and the corresponding meta-data that tells you the image dimensions in pixels, the data type and so on, but in principle you can do it with ImageMagick which is included in most Linux distros and is available for macOS and Windows.
So, using the dataset here sample dataset and knowing the data is unsigned 8 bit and 360x180 pixels, you would run this command in Terminal (or Command Prompt if on Windows):
convert -size 360x180 -depth 8 gray:gl-latlong-1deg-landcover.bsq -auto-level result.tif
If your data is multi-band band-sequential, you may have to use:
convert -size 360x180 -depth 8 -interlace plane rgb:gl-latlong-1deg-landcover.bsq -auto-level result.tif
Or, if you cannot get that to work, you may need to extract each band separately using a byte offset and then combine them afterwards, something like:
convert -size 360x180 -depth 8 gray:image.bsq -auto-level red.tif
convert -size 360x180+64800 -depth 8 gray:image.bsq -auto-level green.tif
convert -size 360x180+129600 -depth 8 gray:image.bsq -auto-level blue.tif
convert red.tif green.tif blue.tif -combine RGB.tif
Note that if you install ImageMagick v7 or newer, the above commands change to:
magick -size ...
rather than:
convert -size ...
Keywords: ImageMagick, command-line, command line, image, image processing, satellite, ENVI, band-sequential, planar, imagery, AVHRR, convert

Mac Terminal - Create animated gif from png files

I have a bunch of png files named as 1.png, 2.png, etc. and I want to create an animated gif image from them all. I haven't been successful in finding a solution for a terminal command that will convert these png files into a single animated gif.
Can someone post some commands that I can try? I have tried "convert" commands but my terminal always says convert is not found even though I have installed ImageMagik.
convert *.png screens.gif
This answer suggested installing convert with brew install ImageMagick.
ImageMagick's convert command works perfectly for this but you'll want to list the filenames in the correct order. Using *.png will jumble frames if the digits don't have the leading zeros because the ordering is alphabetical:
1.png 10.png 11.png 2.png 3.png ...
If you use zsh you can simply use a glob qualifier:
convert *.png(n) out.gif
Otherwise you can sort the ls output
convert $(ls *.png | sort -V) out.gif
If your filenames have leading zeros go ahead and use *.png. Note that the default delay between frames is small, so depending on your use case the frame rate might be too quick. To change that use the -delay option, for example:
convert -delay 50 *.png out.gif
This will set FPS to 100/50 = 2 frames per second.

Command line batch image cropping tool

is there any lightweight command line batch image cropping tool(Linux or Windows) which can handle a variety of the formats ?
In Linux you can use
mogrify -crop {Width}x{Height}+{X}+{Y} +repage image.png
for CLI image manipulation
Imagemagick's convert does the trick for me (and much more than cropping):
convert -crop +100+10 in.jpg out.jpg
crops 100 pixels off the left border, 10 pixels from the top.
convert -crop -100+0 in.jpg out.jpg
crops 100 pixels off the right, and so on. The Imagemagick website knows more:
http://www.imagemagick.org/Usage/crop/#crop
Imagemagick is what you want -- tried and true.
I found nconvert pretty handy so far.
for f in final/**/*;
do
convert -crop 950x654+0+660 "$f" "${f%.jpg}".jpg
done
This script loops through all the sub-folders and crops the .jpg files.
macOS has sips image processing tool integrated. Cropping functions available are:
-c, --cropToHeightWidth pixelsH pixelsW
--cropOffset offsetY offsetH
Easy with sips: just set the offset to start the cropping:
sips --cropOffset 1 1 -c <height> <width> -o output.png input.png
I have scanned some pages and all ~130 pages needs the lower ~1/8 of the page cut off.
Using mogrify didn't work for me,
a#a-NC210-NC110:/media/a/LG/AC/Learn/Math/Calculus/Workshop/clockwise/aa$ mogrify -quality 100 -crop 2592×1850+0+0 *.jpg
mogrify.im6: invalid argument for option `2592×1850+0+0': -crop # error/mogrify.c/MogrifyImageCommand/4232.
However convert did:
a#a-NC210-NC110:~/Pictures/aa$ convert '*.jpg[2596x1825+0+0]' letter%01d.jpg
a#a-NC210-NC110:~/Pictures/aa$
I learnt this here under the Inline Image Crop section.
Notice my syntax: I had to put my geometry in brackets: [].
Using the successful syntax above but with mogrify simply didn't work, producing:
a#a-NC210-NC110:~/Pictures/aa$ mogrify '*.jpg[2596x1825+0+0]' letter%01d.jpg
mogrify.im6: unable to open image `letter%01d.jpg': No such file or directory # error/blob.c/OpenBlob/2638.
Linux a-NC210-NC110 3.13.0-32-generic #57-Ubuntu SMP Tue Jul 15 03:51:12 UTC 2014 i686 i686 i686 GNU/Linux
Lubuntu 14.04 LTS

Can ImageMagick return the image size?

I'm using ImageMagick from the command line to resize images:
convert -size 320x240 image.jpg
However, I don't know how to determine the size of the final image. Since this is a proportional image scale, it's very possible that new image is 100x240 or 320x90 in size (not 320x240).
Can I call the 'convert' command to resize the image and return the new image dimensions? For example, pseudo code:
convert -size 320x240 -return_new_image_dimension image.jpg // returns the new resized image dimensions
-ping option
This option is also recommended as it prevents the entire image from being loaded to memory, as mentioned at: https://stackoverflow.com/a/22393926/895245:
identify -ping -format '%w %h' image.jpg
man identify says:
-ping efficiently determine image attributes
We can for example test it out with some of the humongous images present on Wikimedia's "Large image" category e.g. this ultra high resolution image of Van Gogh's Starry Night which Wikimedia claims is 29,696 × 29,696 pixels, file size: 175.67 MB:
wget -O image.jpg https://upload.wikimedia.org/wikipedia/commons/e/e8/Van_Gogh_-_Starry_Night_-_Google_Art_Project-x0-y0.jpg
time identify -ping -format '%w %h' image.jpg
time identify -format '%w %h' image.jpg
I however observed that -ping at least in this case did not make any difference on the time, maybe it only matters for other image formats?
Tested on ImageMagick 6.9.10, Ubuntu 20.04.
See also: Fast way to get image dimensions (not filesize)
You could use an extra call to identify:
convert -size 320x240 image.jpg; identify -format "%[fx:w]x%[fx:h]" image.jpg
I'm not sure with the %w and %h format. While Photoshop says my picture is 2678x3318 (and I really trust Photoshop), identify gives me:
identify -ping -format '=> %w %h' image.jpg
=> 643x796
(so does [fx:w] and [fx:h])
I had to use
identify -ping -format '=> %[width] %[height]' image.jpg
=> 2678x3318
I don't know what's going on here, but you can see both values on standard output (where the width and height before the => are the correct ones)
identify -ping image.jpg
image.jpg PAM 2678x3318=>643x796 643x796+0+0 16-bit ColorSeparation CMYK 2.047MB 0.000u 0:00.000
The documentation says %w is the current width and %[width] is original width. Confusing.
%w and %h may be correct for most uses, but not for every picture.
If you specify option -verbose, convert prints:
original.jpg=>scaled.jpg JPEG 800x600=>100x75 100x75+0+0 8-bit sRGB 4.12KB 0.020u 0:00.009
^^^^^^

Resources