How does ImageMagick pass options to cwebp Linux - imagemagick

I'm running
$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=debian
I'm also running ImageMagick 6.9.
I'd like to convert a PDF image into WebP. AFAIK, out of the box, ImageMagick on Linux cannot convert to WebP, so I sudo apt-get install webp which installs cwebp.
cwebp allows to specify the -q parameter, and ImageMagick allows to specify the -quality parameter.
When I run $ cwebp -q 90 image.png -o image.webp, it takes cwebp around 8 seconds to convert it. If I run convert image.png -quality 90 image.webp, it takes ImageMagick around 30 seconds to convert it. It seems like the -quality parameter is not passed through to cwebp. It also may be the case that convert attempts to run a lossless conversion, which in cwebp is achieved with an explicit -lossless flag.
I run the test commands for a 10 MB test png image.
I would like to achieve 8 second conversion times with convert command. How can I do it?

I realize you want imagemagick, but if you are able to consider alternatives, libvips can do pdf -> webp quickly at the command line, and without any configuring.
For example, with this PDF (Audi R8 brochure) on my 2015 laptop, I see:
$ time convert -density 600 r8.pdf[3] -quality 90 x.webp
real 0m36.699s
user 0m23.787s
sys 0m1.628s
$ vipsheader x.webp
x.webp: 9921x4961 uchar, 3 bands, srgb, webpload
Which I think is broadly in line with the times you are seeing.
With libvips, I see:
$ time vips copy r8.pdf[dpi=600,page=3] x.webp[Q=90]
real 0m7.195s
user 0m6.861s
sys 0m0.505s
$ vipsheader x.webp
x.webp: 9921x4961 uchar, 3 bands, srgb, webpload
The same result, but within your 8s time budget.
You can set a lot of other webp options if you want more control over compression.

It turns out, that the delegates are invoked using the rules in /etc/ImageMagick-6/delegates.xml.
It lists a bunch of rules on how to convert between different types of images.
For my case, the png->webp conversion, I needed the string:
<delegate decode="png" encode="webp" command=""cwebp" -quiet %Q "%i" -o "%o""/>
While in this file I don't know the -quaility parameter value, and there seems to be no way to capture it.
However, if you wish to keep the value of the -q parameter for cwebp, you have the option of hard-coding the -q $YOUR_VALUE right into the command inside the delegate tag.
This solution is still slower than invoking cwebp directly, since ImageMagick can take up to 8 seconds before invoking the delegate.

Related

Convert png images to lossy avif

I try to compress my ~1MB pngs to get a smaller image.
When I compress my images to jpeg with:
for i in card*.png ; do convert -resize 445x625 -background white -flatten "$i" ../medium/"${i%.*}.jpg" ; done
they end up about 100kb
So I tried
for i in card*.png ; do echo $i; convert -resize 445x625 "$i" ../medium/"${i%.*}.avif" ; done
which results in avif images ~400kb, I guess because they are losslessly compressed.
How do I create lossy compressed avif images? And what would be a useful quality level to get images with the text still clearly readeable?
(I use ImageMagick 6.9.10-23 on Ubuntu)
libheif
You can install
apt install libheif-examples
and then use heif-enc to create heif files with:
for i in card*.png ; do echo $i; heif-enc "$i" -o "${i%.*}.avif" ; done
If you need avif format, you need to compile the latest version of libheif, which has the -A option to create avif files.
(There is a section in the README there how to build it on your system. But at least on Ubuntu this is not leading to a running heif-enc)
Better use avifenc:
# Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
sudo apt install zsh # needed for this pspecific package install
brew install joedrago/repo/avifenc
Now you have the tool to create avif files with the syntax:
avifenc [options] input.[jpg|jpeg|png|y4m] output.avif
(use avifenc --speed 4 --min 20 --max 22 -j 8 to get a higher compression and use all 8 cores)

Command-line image converter\resizer

I'm looking for a command-line image converter/resizer.
What i need to do is convert bitmap and tiff files into png files as well as creating a thumbnail. The images are relatively large. The largest is approximately 13,000 x 10,000 pixels and around 200mb.
I've tried ImageMagick. It used too much memory, was too slow, and couldn't handle the largest files without using disc cache making it unbearably slow.
Currently I'm using GraphicsMagick which uses less memory and can handle the larger files, but it is still a little slow. Around 15s per image.
Are there any other programs out there that could maybe offer a little better performance?
You could try libvips. It's a streaming image processing library, so it's able to read the input, process, and write the output as a single pipeline, with no separate loading phase and no temporary files. It's got a fancy threaded IO system too, so performance is good and memory use is low.
I timed it on this machine (imac with ImageMagick 6.9.6-3 Q16, gm 1.3.25, vips 8.4.2):
$ vips black test.tif 13000 10000 --bands 3
$ ls -l test.tif
-rw-r--r-- 1 john staff 390000854 22 Nov 09:43 test.tif
So that's a 13000 x 10000 3-band, 8 bit uncompressed TIFF. With vipsthumbnail, the image shrinker that comes with vips, I see:
$ /usr/bin/time -l vipsthumbnail test.tif -s 128x128 -o small.png
0.54 real 0.42 user 0.11 sys
77635584 maximum resident set size
I ran three times and picked the fastest, so that should just be a test of vipsthumbnail and not my disk system. That's 0.54s real time, 77MB of peak memory.
With convert I see:
$ /usr/bin/time -l convert test.tif -resize 128x128 small.png
4.87 real 4.28 user 0.55 sys
1432182784 maximum resident set size
Again, fastest of three runs, 4.87s real time, 1.4gb memory. GraphicsMagick is a little faster, I see:
$ /usr/bin/time -l gm convert test.tif -resize 128x128 small.png
3.95 real 3.41 user 0.51 sys
1264369664 maximum resident set size
So 3.95s real, 1.2gb peak memory.
So on this test, libvips is 7x faster and uses 15x less memory than graphicsmagick.
libvips is a standard part of most linuxes, it's in homebrew and macports, and there are 64-bit windows binaries on the vips website.
There are so many image handling software that can convert from any of your choose to your desired out put format ,just download this beautiful software that
can handle all (video,image,audio) and
you don't have to write any command its graphical interface will provide you will all you need and
it runs with little or less memory.
you can convert as much images as you have with desired size and follow your progress while doing another thing.
check this official link of the software http://www.pcfreetime.com/
With either ImageMagick or GraphicsMagick you can speed up PNG encoding by using a lower "-quality" instead of accepting the default quality==75. This will trade compression performance (file size) for speed. Try -quality 40 for line art, or -quality 41 for photos. Here are some results for a JPEG out of my camera, using ImageMagick-7.0.3-8 built with libpng-1.2.54:
glenn.rp> time magick D*88.JPG d88-q75.png
real 0m13.494s user 0m11.252s sys 0m2.060s
glenn.rp> time magick -quality 41 D*88.JPG d88-q41.png
real 0m7.377s user 0m4.728s sys 0m1.908s
glenn.rp> time magick -quality 40 D*88.JPG d88-q40.png
real 0m3.842s user 0m3.200s sys 0m0.584s
glenn.rp> ls -lt d88*
-rw-rw-r-- 1 glennrp glennrp 24352041 Nov 29 15:45 d88-q40.png
-rw-rw-r-- 1 glennrp glennrp 17072518 Nov 29 15:45 d88-q41.png
-rw-rw-r-- 1 glennrp glennrp 15788794 Nov 29 15:44 d88-q75.png

.CDR to .SVG Convert Using ImageMagick

I am on CentOS 6.4 and trying to convert .CDR to .SVG Convert Using ImageMagick using SSH command.
my 1.cdr file is in /var/www/vhosts/website.com/httpdocs/test/1.cdr
once converted to SVG it should be created in the same folder
Tried the following command:
convert /var/www/vhosts/website.com/httpdocs/test/1.cdr image.svg
The Error I am getting is:
sh: mplayer: command not found convert: Delegate failed "mplayer"
"%i" -really-quiet -ao null -vo png:z=3' #
delegate.c/InvokeDelegate/1032. convert: missing an image filename
image.svg' # convert.c/ConvertImageCommand/2800.
Not sure what does that mean ?
In order to convert CDR files you need to install uniconvertor for CDR delegate.
List of all delegates:
convert -list delegate
By default it outputs:
cdr => "uniconvertor" "%i" "%o.svg"; mv "%o.svg" "%o"
Install uniconvertor. For example, on Ubuntu it’s:
sudo apt-get install python-uniconvertor
Then run:
convert image.cdr -flatten -thumbnail '512x512' image.png
Or, with zoom cropping:
convert image.cdr -flatten -thumbnail '512x512^' -gravity center -crop 512x512+0+0 +repage image.png
And you’re done.
I convert to PNG here but you may use your own output format.
python-uniconvertor is part of inkscape.
It does not exist by itself.
Ubuntu/Mint recently removed all the old Python stuff, for Corel Draw I have to fire up the WinXP VM & Corel and export something Linux understands, usually PNG, a favourite
CDR & WMF files are pretty much dead to Linux, ImageMagick can still handle WMF though.

Can't install GhostScript in ImageMagick

Download latest version of ImageMagick. Unpacked it. Installing Ghostscript like this:
$ sudo apt-get install ghostscript
After that try to configure ImageMagick:
$ ./configure --with-gslib
$ make
$ make install
After that i try to conver PDF to jpg
$ sudo /usr/local/bin/convert in.pdf out.jpg
And i see this mistake
convert: no decode delegate for this image format `/tmp/magick-BzHdr4Kp-00000001' # error/constitute.c/ReadImage/544.
convert: Postscript delegate failed `in.PDF': Нет такого файла или каталога # error/pdf.c/ReadPDFImage/678.
convert: no images defined `out.jpg' # error/convert.c/ConvertImageCommand/3044.
What i'm doing wrong?
Try the following convert commands to see more precisely what's possibly going wrong:
convert a.pdf -debug coder a.jpg
convert a.pdf -debug all a.jpg
There will possibly be a lot of output going to stderr. Amongst the lines you may see where IM is looking for Ghostscript. Also, try
convert -list delegate
convert -list delegate | grep --color -E '(eps|pdf)'
to find with which exact commandlines ImageMagick tries to run Ghostscript (it may call gsx instead of gs, or it may look for it in /usr/local/bin/...). If you find any deviations from your real Ghostscript installation, you can possibly fix it by editing delegates.xml.
convert -list configure
will show you how ImageMagick is configured (and if, for example, gs was during compile-time in the list in DELEGATES variables). Here you also find where to look for delegates.xml:
convert -list configure | grep CONFIGURE_PATH
should list the directory where this (as well as some more) *.xml settings files are located which control how convert et al. behave...

How to convert a JPEG image into SVG format using ImageMagick?

How to convert a JPEG image into SVG format using ImageMagick?
you'll need to use potrace and convert to a bitmap first.
$convert input.jpg output.ppm
$potrace -s output.ppm -o svgout.svg
Actually, with a complete installation of a recent version of ImageMagick it should be as easy as:
convert some.jpeg some.svg
Of course, ImageMagick cannot do it all by itself -- it uses delegates (helper programs) to handle SVG input or output. (This has been pointed out by other answers already.)
To see a (partial) list of all delegates (and their respective commands), run
convert -list delegate
To see the config file where all the delegate secrets hide, see
convert -list delegate | grep delegates.xml
To see a (partial) list of SVG handling delegates, run
convert -list delegate | grep -i svg
However, ImageMagick likes to put some of its external helper utilities into 'stealth' mode and doesn't necessarily reveal their presence when using above commands.
Just look into the delegates.xml file itself. On my system it's:
grep -i svg /opt/local/etc/ImageMagick/delegates.xml | grep -i --color stealth
<delegate decode="autotrace" stealth="True" \
command=""/opt/local/bin/convert" "%i" \
"pnm:%u"\n\
"/opt/local/bin/autotrace" \
-input-format pnm \
-output-format svg \
-output-file "%o" "%u""/>
<delegate decode="svg:decode" stealth="True" \
command=""/opt/local/bin/inkscape" "%s" \
--export-png="%s" \
--export-dpi="%s" \
--export-background="%s" \
--export-background-opacity="%s" \
> "%s" 2>&1"/>
As you may see, on my system the ImageMagick installation automatically uses (amongst others)...
...inkscape to convert SVG to PNG;
...autotrace to convert PNM to SVG;
Of course, one could argue the benefits of rather using autotrace directly -- but that would require to manually convert the whatever-input-format to PNM first. So for this preliminary step you'd probably use ImageMagick anyway...
You'll actually need some software or code to vectorize your image in between, as jpg is a raster format, while SVG is a vector format. I don't think imagemagick alone can do that for you.

Resources