How to convert svg to eps using Imagemagick? - imagemagick-convert

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

Related

Add inline .svg image in Rmarkdown

I have used ![](https://image.png){width=25px} for inline image but it seems not working with .svg image.
Is there any way that I can use this image in my rmarkdown?
You could use the R package rsvg to convert the SVG to PDF
rsvg::rsvg_pdf(svg = "https://upload.wikimedia.org/wikipedia/commons/1/15/Florida_in_United_States.svg",
file = "image.pdf")
and then include that PDF as you're used to
![](image.pdf){width=25px}
You could also convert the SVG to another image format supported by knitr using the other rsvg::rsvg_* converter functions, e.g. to PNG via rsvg::rsvg_png(). But I'd recommend to stick with vector image formats like PDF or EPS since they will print in crisp sharpness.
Note that if you install rsvg from source (likely the case on Linux), additional system dependencies are required.

Converting TIFF to PDF with GraphicsMagick MediaBox / CropBox resolution

We are currently converting TIFF files to PDF using GraphicsMagick. The TIFF is coming from an eFAX and has a (pixel) resolution of 1728x2200.
If you do the conversion with tiff2pdf or just open it on Preview and convert export it to PDF, it is generated with a MediaBox value of 612x792 point, which is what is expected.
However graphics magick generates a MediaBox of 1728x4400 and a CropBox of 610x792. It all looks good if you open it on a PDF viewer because it's using the CropBox but if you're feeding it to GhostScript after, you don't get the Image on the full page but as a small square inside the document.
The lazy solutions would be to change for Tiff2PDF or add -dUseCropBox to our GhostScript command but I'd like to know what GraphicsMagick option should be used to have the PDF with the good MediaBox. It's like it doesn't understand that the resolution is in Pixels and not in Point. Hope somebody has insights

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

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.

ImageMagick adds thick horizontal lines to PNGs extracted from PDF

Edit July 7, 2017: Downgrading to ImageMagick 6.9.5 solved this problem, which may be Cygwin-specific. I still don't know the underlying cause.
I need to extract data via OCR from images in PDF reports published by Chicago Public Schools. An example PDF is here (NB: this link downloads the file automatically rather than opening it in the browser). Here's a sample image (from PDF page 11, print page 8), extracted with pdfimages -png version 0.52.0 on Cygwin:
I'd like to crop each bar into its own file and extract the text with OCR. But when I try this with ImageMagick (version 7.0.4-5 Q16 x86_64 2017-01-25 according to convert -version), using the command convert chart.png -crop 320x600+0+0 bar.png, I get this image, with horizontal lines that interfere with OCR:
Running pdfimages to extract to PPM format first and then converting to PNG while cropping gives the same result, as does round-trip converting the extracted images to SVG format with ImageMagick's rsvg delegate, and fiddling with the PNG alpha channel changes the line's colors from gray to white or black but doesn't eliminate them. I've found a workaround of round-trip converting extracted images through JPG (introducing ringing artifacts, which I hope are irrelevant). But I don't see why I should have to do this. Incidentally, ImageMagick introduces the lines to PNGs even if I run a null conversion convert chart.png chart.png, which ought to leave the image unchanged:
I have found other complaints that PDF software adds horizontal lines to images, but none of them exactly matches this problem. A discussion thread mentions that versions of the PDF standard somehow differ in their treatment of alpha channels, but my knowledge of graphics is too poor understand the discussion fully; besides, my images get horizontal lines added after they're extracted from the PDF, because of something internal to ImageMagick. Can anyone shed some light on the causes of the grey lines?
Using the latest ImageMagick 7.0.6.0 Q16 Mac OS X, I get a good result. As mentioned above by Bonzo, the correct syntax for IM 7 is magick rather than convert. The use of convert reverts to IM 6. Also do not use magick convert either.
magick chart.png -crop 320x600+0+0 +repage bar.png
If this does not work for you, then there must have been a bug in your older version of IM 7. So you should then upgrade.
Note also the +repage is needed to remove the virtual canvas

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