Huge whitespace appearing when converting .png to .gif with bash convert - bash

I have a directory called "plots_for_gifs", which contains 105 files, whose names are identical apart from they end in ...000.png, ...001.png ... etc. up to ...104.png. I am trying to convert them to a .gif using:
convert -density 150 -trim -delay 35 -loop 0 ./plots_for_gifs/*.png ./river_diff.gif
The image files are 491x411 pixels, however the gif produced is 7017x4958 pixels! Even though I am including "-trim", and the same occurs even if I add "-size 491x411"... any ideas?
I am running this in a bash shell in Ubuntu 16.04.3.

Mmmmm.... a couple of things.
You don't need -density at all with PNG files because it only sets the density to be used when rasterising vector files such as SVG. So, you can omit that.
If, as you say, your images are already the correct size, you don't need -trim. So, you can omit that too.
You don't need to prefix filenames with ./, as that just means "the current directory" which is the default anyway, so you can omit that.
Now to the actual problem. I guess your PNG files have been cropped from some larger images and have "remembered" their previous canvas size. The best way to make them forget, is to use +repage after loading them.
So, without seeing your files, I suspect you want something more like:
convert -delay 35 -loop 0 plots_for_gifs/*.png +repage river_diff.gif
If you find you do need -trim, add it into the above command before +repage.
If that doesn't work, please run the following command and paste the output in your original question - by clicking edit underneath it:
identify plots_for_gifs/*000.png

Related

File too big when converting pdf to jpg using ImageMagick/Ghostscript

I'm trying to have an identical output to what Adobe Acrobat does with File>>Save As>>Image>>JPEG. But whenever I use ImageMagick's convert it takes much longer and the resulting file is 2-3x bigger. I set the density option to -density 686 because that was the density of Acrobat's output according to the following:
Here is the result of convert (filename changed to Bitter_Creek.jpg), not sure why it says aspect ratio and the dimensions will still differ even when setting the size option to -size 14859x18388
Using the ls -l command to describe the resulting JPGs I get this:
(top file is result of ImageMagick's convert and the bottom file is result of Acrobat's Save As:
I would like to know which options to use to get an identical output.
Filesize of a jpeg image depends on quality setting. The default setting of Acrobat is "Medium" whose quality value is considerably low (62), whereas ImageMagick's convert is defaulted to higher value.
If you expect the equivalent result, add -quality 62 option to convert, although picture quality will be accordingly degraded.

Comparing the same images with different format(.jpg, .bmp, .png, etc)

I need to check if 2 images have been modified. I have the original image which I input it through 2 different tools, finally resulting the 2nd image.
The tools only alter the format of the image; the inputted image can be of any type (.jpg, .bmp, etc), and the first tool converts the image to .bmp and the second tool converts it to .png.
How can I check if the images display the same thing, with a certain threshold of course. (via cmd if possible, after that I'll write a script in Ruby)
ImageMagick can handle this by compare command.
Usage:
compare im1.png im2.bmp result.jpg
It marks the changed areas with red. After that you can easily check if it's changed or not.
Example: (Note that input images are from slightly different angles, so they are not the same.)
compare orig0.bmp orig1.jpg compare.jpg
orig0.bmp
orig1.jpg
compare.jpg

Is there a way to know the offsets of interlacing blocks in image files?

That is, if I have image.png and it happens to be an interlaced image, I would like to split the file at the exact offsets where an interlacing block is present. I would like to have the same thing for progressive .jpg files.
I can read the specs and try to figure it out from there, but it would be nice if such a thing existed in e.g. ImageMagic or any other library/tool.

MiniMagick's "strip" function makes picture filesize bigger

I have used MiniMagick to compress JPEG files.
With strip function, I want to get rid of EXIF from image. So, I do:
image = MiniMagick::Image.open("my_picture.jpg")
image.strip
image.write("my_picture_small.jpg")
but sometimes the size of my_picture_small.jpg is bigger than my_picture.jpg.
However, when I don't use the strip function, like
image = MiniMagick::Image.open("my_picture.jpg")
# image.strip
image.write("my_picture_small.jpg")
my_picture_small.jpg's size is smaller.
That situation happened with some picture deal with Photoshop and in my CentOS computer, but run well with my Macbook. I don't know why stripping some information led to more storage.
Can anyone explain it?
Have found that ImageMagick will recompress image even if it with any arguments, such as
convert image.jpg new_image.jpg
new_image.jpg will be different from image.jpg more or less. If image.jpg is from a phone or camera or a image processing tools, the degree of difference is also different.
So compress images with MiniMagick or Rmagick that use ImageMagick as there system support, just do convert -strip image.jpg new_image.jpg may led to a unexpected result, avoid to use MiniMagick command if there is no need to greatly compress file.

Divide large image into A4 sized images

I would like to split a large PNG file into A4 pages so they can be printed out easily.
I would like to use a Linux command line script to do this:
shell> split-into-a4-sized-pages some-big.png
I assume you have ImageMagick & pdfposter installed.
A) convert your .png to .pdf (using ImageMagick)
convert input0.png input1.pdf
B) tile your image using pdfposter:
pdfposter -s4 input1.pdf out.pdf
this command enlarges input0 exactly 4 times, print on the default A4
media, and let pdfposter determine the number of pages required.
Try using imagemagick's crop to your desired size.
Say you have a 640x962 image:
and you want to crop it into 4 320x481 images:
Use:
convert pexels-adonyi-gábor-1400172.jpg -crop 240x240+0+0 cropped.jpg
convert pexels-adonyi-gábor-1400172.jpg -crop 320x481+320+0 cropped.jpg
convert pexels-adonyi-gábor-1400172.jpg -crop 320x481+0+481 cropped.jpg
convert pexels-adonyi-gábor-1400172.jpg -crop 320x481+320+481 cropped.jpg
Now you'd have to find out how many pixels fit into an A4 page in your printer, and the dimensions of the image, and it is a very simple script from here.
Photo by Adonyi Gábor from Pexels.
You can use convert of ImageMagick to scale the image; there are probably other tools in ImageMagick to clip the image if you want.
I don't know of any ready-made command line tool to do this. Unless you use it all the time, ImageMagick may take longer to figure out the right combination of commands and options, than to write a quickie program.
An easy way, if you know Python at all, is write a few-line program using PIL (Python Imaging Library). To read an image takes one line. To extract chunks of some width and height at specified location to save as new image files, is also easy. Add a couple for loops to scan rows and columns of A4-sized chunks, and you're done.
If you don't know Python, just about all quick-to-write programming languages have a similar capability. The GD library comes to mind; it has bindings for several languages.
NetPBM's pamdice will do the splitting into multiple pages. You'll have to set the -width and -height options according to the DPI of your desired A4 images.
And you'll also have to convert the input image to netpbm format first with pngtopam:
pngtopam big.png | pamdice -outstem tile -height h -width w
That will leave you will a bunch of files called tile_x_y.ppm
Convert each one of those to PNG with pnmtopng

Resources