How to get optimal result when converting SVG to PDF with ImageMagick? - imagemagick

In Windows 10, I use ImageMagick-7.0.10-Q16. When I execute this command-line:
magick clocky.svg test.pdf
... then I get a PDF where the image in the PDF is very pixelated:
This is the source SVG image: https://svgshare.com/s/V0f
How can I get an optimal result when converting SVG to PDF without pixelation with ImageMagick?
Isn't there a way to include the SVG natively in the PDF, so the image in the PDF looks always smooth at all zoom values? (Like it is obviously done by Inkscape when saving an SVG to PDF).

In ImageMagick, you would specify a density before reading the SVG and then resize afterwards. So
magick -density 288 clocky.svg -resize 25% test.pdf
288=4*72 so we resize by 1/4=25%

Related

How to restrict tiff file size using ImageMagick and python?

I am converting a pdf to .tiff file using ImageMagick and calling it from python using subprocess,run() but, I want the output file size to be limited to a maximum value say 40MB. -define extent max_value is not working for tiff like it works for jpeg images.
This is my code:
subprocess.run('magick convert -density 150 example.pdf -trim -thumbnail 500 result%04d.tif')

imagemagick convert RGB PNG to CMYK PDF

I am trying to create a PDF file using Latex. However, Latex does not handle TIFF or any other image format capable of both transparency and CMYK. The only solution I think I can use is to convert the PNG image to PDF and embed those in the file.
I am somewhat familiar with imagemagick, however, I am having trouble figuring out how to convert a PNG (probably in the RGB/SRGB colour space) to a PDF in the CMYK colour space.
How do I go about doing this conversion so that the colours are correct and the transparency remains?
In Imagemagick, you should use a CMYK type profile to do the conversion:
convert input.png -profile USWebCoatedSWOP.icc output.pdf
Note, however, that Imagemagick will simply put the raster image into a vector PDF shell. It will not vectorize the image.

Retaining colour compoent when doing OCR using Image magick - tesseract

My initial input is a colour multi column JPG file. I run image magick on this to create a TIFF file which tesseract 4.0 then performs OCR on to convert the TIFF to a PDF with the text in a searchable form.
Problem with this is because the TIFF output from Imagemagick is monochrome ( which is has to be for tesseract to extract the text correctly ) the final PDF is monochrome with the text highlightable on it. What I am trying to figure out is , is there a way to retain the colour of the original document when Imagemagick converts it to TIFF?
I am running on Ubuntu 14.0
The goal is to start with a coloured JPG image ( book scan but I don't have control over the scan process so always get a JPG ) which has text on it and convert this to a PDF file which looks the same as the JPG but with the text in a searchable/highlightable format.
My imageMagick command to convert the JPG to tiff is
convert -density 300 MyImage.jpg -depth 8 -lat 30x30-5% MyImage.tiff
MyImage.tiff is black and white which works best for Tesseract to to its OCR.
Tesseract command to convert to PDF is
tesseract MyImage.tiff MyImage pdf
But the final PDF will be black and white. What I would want to have is the text overlayed on a colour version of the original JPG.
Tesseract will only give decent results if using a monochrome input tiff file

Crop and scale SVG to PNG using ImageMagick, without pixellation

I have an SVG with many polygons:
https://github.com/barrycarter/bcapps/blob/master/sample-data/current-temps.svg
that looks somewhat like this:
Cropping this and converting to PNG works fine:
convert -crop 100x100+200+150 current-temps.svg /tmp/exhb2.png
Cropping and scaling, however, fails:
convert -crop 100x100+200+150 -scale 1000x750 current-temps.svg /tmp/exhb3.png
How do I make ImageMagick "zoom into" the SVG before cropping?
(I realize ImageMagick can only read, not write, the SVG format, but
it should still be able to do what I want?)
EDIT/SOLVED:
Thanks, robermorales.
inkscape -z -e out4.png -w 1000 -h 1000 -a 200:200:400:400 current-temps.svg
(for example) worked like a charm.
I also realized that copying the SVG, tweaking the transform line:
<g transform="scale(3,3) rotate(-90) translate(-90,180)">
and then converting to PNG is another solution.
Try doing scale before crop.
However, doing that using inkscape cli is easier.
Sorry for no links, afk
Don't crop an SVG into PNG.
You can use viewBox to re-define the crop area then convert that SVG into PNG in highest solution as possible.
Check this post https://www.sarasoueidan.com/blog/svg-coordinate-systems/ explain what is viewBox and you will got my idea.
Proper ImageMagick syntax here is to read the input, then crop, then resize. See http://www.imagemagick.org/Usage/basics/#why Though that is not likely the issue. The issue is that -scale will replicated pixels and so make it blocky. You should replace -scale with -resize. That will be smoother, but blurry for the amount of magnification you are requesting. Try this command:
convert current-temps.svg -crop 100x100+200+150 -resize 1000x750 exhb3.png

Converting .eps to .jpg

Our print team saves raster images as .eps files. We need to convert about 11000 .eps to .jpg. We are using ImageMagick (with Ghostprint) on Linux. The conversion occurs but the resulting .jpg is not the same size as the source .eps - It's about 1/2 the size. Probably a problem converting a vector to a raster. Any way to solve this?
Your using the default resolution (72dpi). use the -density option to specify a dpi to convert.
convert -density 300 /path/to/file.eps -flatten /path/to/file/.jpg;

Resources