gm convert: Unrecognized units type - imagemagick-convert

I try to compress PNG by GraphicsMagick(1.3.23 Q8), here is the command:
gm convert -units Undefined -type palette -define png:format=png8 src.png dest.png
and it comes with error:
gm convert: Unrecognized units type (Undefined).
"gm convert -help" shows that units type supports PixelsPerInch, PixelsPerCentimeter, or Undefined.
Acctually, I also try ImageMagick(7.0.1-6 Q8 x86_64),and the command following works fine:
convert -units Undefined -type palette -define png:format=png8 src.png dest.png
I am confused about the error.

Use "+units" instead of "-units Undefined" (this works with both ImageMagick and GraphicsMagick). In general, you can use "+option" to turn off most options. The documentation should be clarified.

Related

Why is magick giving an error while converting base64 files?

I have a bunch of base64 encoded images which I want to convert to their corresponding image files using magick (ImageMagick version 7). I can paste the base64 directly into various online converters which works. But command-line magick is failing.
Example of a file is attached in "x.txt". Pasting it into an online converter like https://onlinejpgtools.com/convert-base64-to-jpg readily yields an image. But this command line fails:
magick inline:`cat x.txt` x.png
This says "magick: corrupt image". If I remove the "inline" part, I get "magick: unable to open image". Here is a link to download the sample file x.txt:
In Imagemagick, try (no cat). That works for me.
magick inline:x.txt x.png
Or pipe from cat to magick as
cat tmp.txt | magick inline:- y.png

How to crop 486 pixels from the bottom of each JPG image in the folder with ImageMagick?

How to crop 486 pixels from the bottom of each JPG image in the folder with ImageMagick?
The following command
magick -crop -0-486 *.jpg
says
magick.EXE: no images found for operation `-crop' at CLI arg 1 # error/operation.c/CLIOption/524
magick.EXE: no image to apply a property "%w" # warning/property.c/GetMagickPropertyLetter/2561.
magick.EXE: unknown image property "%w" # warning/property.c/InterpretImageProperties/3499.
magick.EXE: no image to apply a property "%h" # warning/property.c/GetMagickPropertyLetter/2449.
magick.EXE: unknown image property "%h" # warning/property.c/InterpretImageProperties/3499.
magick.EXE: no image to apply a property "%m" # warning/property.c/GetMagickPropertyLetter/2480.
magick.EXE: unknown image property "%m" # warning/property.c/InterpretImageProperties/3499.
Please, give specific example, internet in controversal (various names like mogrify, convert, various commands etc). Also don't point to ImageMagick "Talmud". Need just a simple example.
OS is Windows, Magick is installed with Chocolatey.
Please make a backup of your images before using the following commands.
The command for a single image is convert or if you have ImageMagick 7+, it is magick.
The command for multiple images is mogrify, or if you have ImageMagick 7+, it is magick mogrify.
The command you want is as follows and it will chop 486 pixels off the bottom of each image in the current directory:
magick mogrify -gravity south -chop x486 *.jpg
The main ImageMagick command command used to be called convert but there is a Microsoft tool with the same name that has caused confusion for years, so all the ImageMagick commands were prefixed with magick, followed by the old name. So,
animate ...
becomes:
magick animate ...
And
mogrify ...
becomes:
magick mogrify ...
In the case of convert, which is the most common usage, you can now use
magick convert ...
or simply
magick ...
where convert is implied.

How to link Fred's Magick Script TextCleaner with XCode Project

I decided to rephrase the question. Here is the problem:
I've managed to run textcleaner.exe within my c++ program by calling:
system("/usr/local/bin/textcleaner g -e normalize -f 25 -o 10 [path to infile] [path to outfile]");
But now I get the error:
/usr/local/bin/textcleaner: line 389: convert: command not found
/usr/local/bin/textcleaner: line 400: [: : integer expression expected
/usr/local/bin/textcleaner: line 403: convert: command not found
/usr/local/bin/textcleaner: line 417: [: : integer expression expected
/usr/local/bin/textcleaner: line 423: [: : integer expression expected
/usr/local/bin/textcleaner: line 429: convert: command not found
--- FILE /Users/~/Desktop/kimlik/kimlik1.bmp NOT READABLE OR HAS ZERO SIZE ---
So what is the problem here? I am giving a correct image with the right path, so I think instead of the last line, the problem lies with the convert command within textcleaner.exe. How can I call textcleaner.exe and convert.exe at the same time so that when running the textcleaner.exe, it knows what command convert is?
I wouldn't recommend calling an external script from a C++ application. You'll need to worry about paths, loading shell environments, and external error handling. Not really hard to do, but I feel unnecessary. I would argue that if your developing a C++ solution, than integrate with Magick++ directly. Try the following...
Ensure that you installed ImageMagick with Magick++ support. This is usually enabled by default.
Update Xcode's Build Settings to include Magick++ flags.
Run Magick++-config --cxxflags in your terminal. The return values should be copied under "Other C++ Flags" option.
Run Magick++-config --libs in your terminal. The return values should be copied under "Other Linker Flags" option.
Xcode project should now support Magick++ library.
Finally, evaluate the source of Fred's fantastic textcleaner script. You should be able to mimic his techniques directly in C++.
For example. The script may generate the following convert command.
convert \( $infile -colorspace gray -type grayscale -contrast-stretch 0 \) \
\( -clone 0 -colorspace gray -negate -lat ${filtersize}x${filtersize}+${offset}% -contrast-stretch 0 \) \
-compose copy_opacity -composite -fill "$bgcolor" -opaque none \
-sharpen 0x1 \ $outfile
Which can be implemented with something like...
#include <Magick++.h>
using namespace Magick;
int main(int argc, const char * argv[]) {
long
filtersize = 15,
offest = 5;
const char
* bgcolor = "white",
* infile = "wizard:",
* outfile = "output.png";
InitializeMagick(argv[0]);
Image alphaImage(infile);
alphaImage.colorSpaceType(GRAYColorspace);
alphaImage.type(GrayscaleType);
alphaImage.contrastStretch(0, QuantumRange);
Image betaImage(alphaImage);
betaImage.negate();
betaImage.adaptiveThreshold(filtersize, filtersize, offest);
betaImage.contrastStretch(0, QuantumRange);
alphaImage.composite(betaImage, 0, 0, CopyAlphaCompositeOp);
alphaImage.fillColor(Color(bgcolor));
alphaImage.opaque(Color("none"), Color(bgcolor));
alphaImage.sharpen();
alphaImage.write(outfile);
return 0;
}

Imagemagick parameters in Bash variables are not interpreted properly?

I need to dinamically compose an image using Imagemagick with a canvas as a base and some other images on top of that.
Currently, the most simple scenario just works (please notice you will need two images named src1.png and src2.png for this to work):
convert src1.png -gravity northwest -draw 'image Over 10,10 0,0 "src2.png"' result.png
However, I need to dinamically forge these parameters to be able to draw one, two or more images on top of src1.png.
To do that, I tried storing the parameters in a variable, and then doing a substitution. I tried two versions of this, both with arrays and with simple strings:
DRAWOPTS=(-draw 'image Over 10,10 0,0 \"src2.png\"')
convert src1.png -gravity northwest ${DRAWOPTS[#]} result.png
DRAWOPTS="-draw 'image Over 10,10 0,0 \"src2.png\"'"
convert src1.png -gravity northwest $DRAWOPTS result.png
But I always get these errors:
convert.im6: non-conforming drawing primitive definition `image' # error/draw.c/DrawImage/3160.
convert.im6: unable to open image `Over': No such file or directory # error/blob.c/OpenBlob/2641.
convert.im6: no decode delegate for this image format `Over' # error/constitute.c/ReadImage/544.
convert.im6: unable to open image `10,10': No such file or directory # error/blob.c/OpenBlob/2641.
convert.im6: no decode delegate for this image format `10,10' # error/constitute.c/ReadImage/544.
convert.im6: unable to open image `0,0': No such file or directory # error/blob.c/OpenBlob/2641.
convert.im6: no decode delegate for this image format `0,0' # error/constitute.c/ReadImage/544.
convert.im6: unable to open image `"src2.png"'': No such file or directory # error/blob.c/OpenBlob/2641.
convert.im6: no decode delegate for this image format `"src2.png"'' # error/constitute.c/ReadImage/544.
convert.im6: non-conforming drawing primitive definition `image' # error/draw.c/DrawImage/3160.
And I can't get this to work. Need some help with this quoting hell, please.
You need to quote the expansion of the array.
DRAWOPTS=( -draw 'image Over 10,10 0,0 "src2.png"' )
convert src1.png -gravity northwest "${DRAWOPTS[#]}" result.png

Converting tiff to mode 1 bit images

Is it possible to convert a tiff image to mode 1-bit image using command line tools. I saw it can be done with gimp but I need to run a script so I prefer a solution using packages like imagemagick etc
If the image contents is already black and white, and you just need to convert, use:
convert input.tif -depth 1 output.tif
If you also require to threshold the image, use something like:
convert input.tif -separate -black-threshold 128 -depth 1 output.tif

Resources