How to convert a JPEG to a JPEG with EXIF orientation 1? - image

If you take a JPEG picture in a non-native orientation for the CCD, most cameras don't bother rotating the raw image. They just (lazily) modify the Orientation value in the EXIF metadata and make the image viewer deal with it. You can check this value by installing ExifTool (via APT) and running exiftool -Orientation -n image.jpg. (This will give you the raw number value found in the data, for a human-readable output remove the -n.)
Is there an Ubuntu/Linux tool or way to modify a JPEG image so that the raw image is rotated to the correct orientation when the EXIF orientation value is set to 1?

I think you want ImageMagick’s auto-orient feature. So, for one image:
convert input.jpg -auto-orient result.jpg
Or, if you have lots to do, make a backup first, then:
mogrify -auto-orient *.jpg
Note this will alter all your files irreversibly, so backup first and check it’s what you want.

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.

Can a PNG image contain multiple pages?

On OSX I converted a multi-page PDF file to PNG and (somehow) it created a multi-page PNG file.
Is there an extension to the PNG format that allows this? Or is this not something I can validly create?
~~~~
To clarify, this is a PNG file, per the builtin file command and the identify command from imagemagick.
$ file algorithms-combined-print.png
algorithms-combined-print.png: PNG image data, 1275 x 1650, 8-bit/color RGBA, non-interlaced
$ identify algorithms-combined-print.png
algorithms-combined-print.png PNG 1275x1650 1275x1650+0+0 8-bit sRGB 3.537MB 0.000u 0:00.000
And here is a pastebin of the command identify -verbose algorithms-combined-print.png: http://pastebin.com/hw1yuRKa
What is notable from that output is that the pixel count is Number pixels: 2.104M which corresponds to one page. However, the file size is 3.537MB, which is clearly sufficient to hold all the pages.
Per request, here is the output of pngcheck: http://pastebin.com/aCRMEd9L
PNG does not support "multipage" images.
MNG is a PNG variant that supports multiple images - mostly for animations, but it's not a real PNG image (diffent signature/header), and has never become popular.
APNG is a similar attempt, but more focused on animations - it's more popular and alive, though it's less official - it's also PNG compatible (a standard PNG viewer, unaware of APNG, will display it as a single PNG image).
Another possible explanation is that your image is actually a TIFF image with a wrong .png extension, and the viewer ignores it.
The only way to know for sure is to look inside the image file itself (at least to the first bytes)
Update: given the pngcheck output, it seems to be a APNG file.

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.

How to convert svg to eps using Imagemagick?

I am trying to convert svg image to eps using Imagemagick. I am able to convert the image using Imagemagick, but the image size is too high when compared to the original image size and the content is not displayed correctly compared to the svg.
I was just wondering this too. However, it appears that Imagemagick might not be the best tool to do this.
Imagemagick is a "raster image processor," but SVG and EPS are vector formats. So using Imagemagick will cause those images to lose information as it has to convert from a vector format, to a raster format, and then back to vector. This probably explains why the contents of your image aren't correctly displayed.
Maybe consider using Inkscape to do this conversion using the following
# Works as of Version 0.92.4
inkscape ing.svg \
-E out.eps \
--export-ignore-filters \
--export-ps-level=3
where the -E flag is short for --export-eps to export EPS files.
Source:
http://imagemagick.org/Usage/formats/#vector
https://stackoverflow.com/a/30539923/6873133

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