Recipe to generate Windows ICO files with Graphicsmagick - imagemagick

Based on this question for imagemagick, what is the equivalent for graphicsmagick? Recipe for creating Windows ICO files with ImageMagick?
Also I just want to generate a fully transparent ico file with multiple sizes. I found that there's an xc:none option that works for both, but is there one single command that generates ico files with multiple sizes that is transparent? Otherwise I would have to first create a transparent png file, then create ico files from the png file.

AFAIK, GraphicsMagick doesn't support writing ICO format files - see here.
Just in case anyone knows more about this mad Microsoft format and if it is maybe some sort of multi-page TIF or GIF in disguise that just needs to be renamed, the following would be one way of making a recipe in GraphicsMagick:
#!/bin/bash
{ echo convert image.png mpr:initial;
echo convert mpr:initial -resize 16x16 mpr:16;
echo convert mpr:initial -resize 32x32 mpr:32;
echo convert mpr:initial -resize 48x48 mpr:48;
echo convert mpr:initial -resize 64x64 mpr:64;
echo convert mpr:16 mpr:32 mpr:48 mpr:64 -colors 256 favicon.tif; } | gm batch -prompt off
For the moment, I have created a multi-page TIF as the output file and it contains the four sizes you need - but as I said, GraphicsMagick will not write a ICO file.

Related

Convert pdf to image with imagemagick and get the list of outputted files

I found how to convert my pdf into png files with the convert command. It is great because out of the box it creates an image for each pages in the pdf which is exacly what I need. The thing is I don't know in advance how many pages my pdf has, so I don't know how many pages convert has created. I looked and looked on the Internet and read the imagemagick site but could not find an appropriate way to output the information I need.
I need a very simple output, something like this:
$ convert in.pdf out.png
out-0.png
out-1.png
out-2.png
...
In ImageMagick, just do:
identify in.pdf
in.pdf[0] PDF 256x256 256x256+0+0 16-bit sRGB 139350B 0.000u 0:00.002
in.pdf[1] PDF 256x256 256x256+0+0 16-bit sRGB 139350B 0.010u 0:00.001
in.pdf[2] PDF 256x256 256x256+0+0 16-bit sRGB 139350B 0.010u 0:00.000
or if you only want the names, then
identify -format "%f[%p]\n" in.pdf
in.pdf[0]
in.pdf[1]
in.pdf[2]
or if you just want to know the number of pages:
identify -format "%n\n" in.pdf | head -n 1
3
Note without the pipe to head, you will get 3 repeated 3 times
See
https://imagemagick.org/script/identify.php
https://imagemagick.org/script/escape.php

How do I convert a CMYK tif with unknown profile to png (RBG)?

I am trying to convert a tiff CMYK image to PNG and cannot find out the ICC profile, which leads to wrong colors in the converted PNG.
I tried the following to determine the profile:
$ identify -format "%[profile:icc]" test.tif
With no result.
And, the following, with no usable result:
$ identify -verbose test.tiff |grep -i profile
crs:CameraProfile: Adobe Standard
crs:CameraProfileDigest: 3DA8CE4A626CE36A1D0C55BF157793C9
crs:LensProfileEnable: 0
crs:LensProfileSetup: LensDefaults
Profiles:
Profile-8bim: 8730 bytes
Profile-tiff:37724: 3132408 bytes
Profile-xmp: 30533 bytes
After that I downloaded Adobe's profiles and tried each of them, but not a single one did work. This is how I tried to apply the profiles:
convert -profile CMYKProfiles.icc -profile AppleRGB.icc -colorspace rgb test.tif test.png
That works, but only if I know the profile and supply the right profile. In my case that doesn't work.
Is the image just broken or is there a way to convert it preserving its colors?
Your file has 4 layers or pages. The one you want seems to be the first layer/page. Each is CMYK with no color profile. Without profiles, it is possible that each display device might show the image differently depending upon what default profile is used, if any.
But with Imagemagick, I get pretty close using USWebCoatedSwop.icc and sRGB.icc profiles as follows
convert -quiet test.tif[0] -profile /Users/fred/images/profiles/USWebCoatedSwop.icc -profile /Users/fred/images/profiles/sRGB.icc test.png
test.png

How to use mogrify (ImageMagick) to convert from NEF to *.jpg and retain EXIF data?

I'm converting about 9000 photos from .NEF to .jpg.
I'd like to retain all EXIF data, most importantly Date and time created, Latidude and Longitude.
I'd like the JPGs to be at the highest possible quality.
I've just gotten started using ImageMagick from the command line. I also have Exiftool installed. I'm using the mogrify command because it handles batches nicely.
When I run
mogrify -format jpg *.NEF
All of my .NEF files are successfully converted to JPGs, but all EXIF data are lost.
I've searched around quite a bit to try and find a solution to this and it seems like I may have to install ufraw, but if possible I'd like a solution that uses software I already have - ImageMagick and Exiftool.
Thanks in advance for any advice you have about how to do this.
Update:
The images I converted using mogrify are slightly smaller (~ 1-2 MB) than those output by my colleague using picasa to convert NEF to JPG. But when I specify -quality 100 in ImageMagick the image sizes gain about 45 MB! Why?
The code exiftool -tagsfromfile %d%f.NEF -ext jpg -overwrite_original . adds the exif information to the JPGs.
Think twice before doing this - you really are discarding a lot of information - and if you don't want it, why not shoot JPEG instead of RAW in the first place?
FWIW, you can use ImageMagick to get the JPEG:
convert somefile.NEF somefile.jpg
Then you can copy the tags across from the original to the file newly created by ImageMagick:
exiftool -tagsfromfile somefile.NEF -all:all somefile.jpg
If you have thousands of images, and are on macOS or a decent Linux/Unix-based OS, I would recommend GNU Parallel like this and it will keep busy all those lovely cores that you paid Intel so dearly for:
parallel --dry-run 'convert {} {.}.jpg; exiftool -tagsfromfile {} -all:all {.}.jpg' ::: *nef
Sample Output
convert a.nef a.jpg; exiftool -tagsfromfile a.nef -all:all a.jpg
convert b.nef b.jpg; exiftool -tagsfromfile b.nef -all:all b.jpg
and if that looks good remove the --dry-run so it actually runs the command.
If you are on Windows, you will have to do some ad-hoc jiggery-pokery to get it done in any reasonable time frame. You can use the mogrify command and get all the conversions done to JPEG and then do all the exiftool re-embedding of the EXIF data later. If your files are named with some sort of system with incrementing numbers, you can start two or three copies of mogrify in parallel - say one doing files whose names end in [0-4] and another one doing files whose names end in [5-9]. I don't speak Windows, but that would probably look like these two commands each running in its own Command Prompt:
mogrify -format jpg *0.NEF *1.NEF *2.NEF *3.NEF *4.NEF
mogrify -format jpg *5.NEF *6.NEF *7.NEF *8.NEF *9.NEF
Then you would do the exiftool stuff when they had all finished but you would have to use a FOR loop like this:
FOR %%G IN (*.NEF) DO (
exiftool -tagsfromfile %%G -all:all %%~dpnG.jpg
)
The %%~dpnG part is a guess based on this answer.

How to convert .xcf files to .png files in batch?

I'm using Windows. I have a folder with .xcf files, each 100x100px. I would like to run a process that will convert them to .png files making them 40x40px. How can I do that?
You might succeed using ImageMagick which also supports XCF for reading. They also provide Windows binaries. The tool also has various transformation (scaling) options, so you can convert and scale each image with one call:
convert source.xcf -resize 40x40 target.png
I'm not fluent with Windows batch programming and don't have access to Windows PC right now, I think a simple loop would look something like this:
for %%f in (*.xcf) do (
convert %%f -resize 40x40 %%~nf.png
)

ImageMagick or Ghostscript: Create Image from PDF

I'm working on a big problem: I have to create a perfect colored JPEG from a PDF file. But there still small differences in green or blue color. I'm using Ghostscript version 8.71 on a Debian system.
Original PDF file:
http://content.test.de/configurations/82/e2/82e2897f5448e73769655317e8fdee77/output.pdf
The simple way via
convert output.pdf -density 600 -quality 100 output.jpg
Result:
http://content.test.de/configurations/82/e2/82e2897f5448e73769655317e8fdee77/output-0.jpg
creates a very light green having nothing to do with the color in the PDF.
After that I tried two other ways with better results, but not perfect:
Via ImageMagick:
convert output.pdf -profile sRGB_v4_ICC_preference.icc \
-density 600 -quality 100 test.jpg
convert -profile ISOcoated_v2_eci.icc -profile eciRGB_v2.icc \
-quality 100 test-1.jpg finish-1.png
Result: Links like before with filename "finish-0.png" (I can just write two links).
Via Ghostscript:
gs -dNOPAUSE -sDEVICE=jpegcmyk -dFirstPage=1 -dLastPage=237 \
-sOutputFile=image%d.jpg -dJPEGQ=95 -dUseCIEColor -g850x610 \
-dPDFFitPage -r300 -q output.pdf -c quit
Result: Links like before with filename "image1.jpg" (I can just write two links).
Anybody has an idea to get a perfect result?
First, use a recent version of Ghostscript, 8.71 is 3 years old. Versions prior to 9.0 will use standard PostScript colour conversions, 9.0 onwards use Little CMS. Your PDF file uses ICC profile based colour spaces with 3 components (RGB), PostScritp RGB->CMYK is fast but inaccurate, so best not to do that.
I believe that if you use a decently up to date version you will find the results adequate without any further tweaking. Do NOT use -dUseCIEColor! That's a horrible PostScript kludge.
It also looks like the jpegcmyk device isn't doing proper colour management, is there a reason you can't use the jpeg device ?

Resources