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

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;
}

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.

gm convert: Unrecognized units type

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.

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

Ghostscript command line parameters to convert EPS to PDF

Just installed Ghostscript 8.54 for Windows.
Does anyone know of the minimum parameters to pass to gswin32c.exe to make it convert, say, someFile.eps to someFile.eps.pdf?
Since the question was about the "minimum parameters to pass to gswin32c.exe to make it convert, say, someFile.eps to someFile.eps.pdf", let me give an answer:
c:/path/to/gswin32c.exe ^
-sDEVICE=pdfwrite ^
-o c:/path/to/output.pdf ^
c:/path/to/input.eps
or even shorter:
gswin32c ^
-sDEVICE=pdfwrite ^
-o output.pdf ^
input.eps
This will use the builtin, default parameters for Ghostscript. The most important of which, from the top of my head, for the most recent version of Ghostscript are:
-dPDFSETTINGS=/default ........ roughly the same settings as Adobe Distiller uses for "screen" with the following differences:
-r720x720 .................................. resolution: 720 dpi (bitmaps/fonts requiring conversion to bitmap)
-dColorConversionStrategy=/LeaveColorUnchanged ... (Distiller's "screen" uses =/sRGB)
-dCompatibilityLevel=1.4 .... (Distiller's "screen" uses =1.3)
-dEmbedAllFonts=true [*]......... (Distiller's "screen" uses =false)
-dOptimize=false [**] ............... (Distiller's "screen" uses =true)
-dDownsample{Color,Gray,Mono}Images=false ... (Distiller's "screen" uses =true)
[*] By default, Ghostscript does not embed the classical "Base 14"-PostScript fonts. To enforce that, use an extra parameter (at the end of the command line!) like -c "<</NeverEmbed [ ]>>setdistillerparams" -f c:/path/to/input.pdf.
[**] Ghostscript's pdfwrite device cannot "optimize" a PDF when it is writing it the first time. To optimize, you have to call Ghostscript again for a second pass, using special parameters (you may also try -dOptimize=true).
BTW, Ghostscript's most recent version is 8.71, available here: ghostscript.com/relases.
Under Windows, ps2pdf and other utilities are located in C:\Program Files\gs\gs#.##\lib as .bat and .cmd files. This isn't exactly obvious, especially if you're looking for .exe files.

Resources