Imagick::getImageInterlaceScheme is deprecated but I can't find a way to replace it in the code.
I tried with Imagick::getInterlaceSchema but it returns different values for the same image.
Does anybody know what would be the proper way to replace this function calls?
Thank you!
EDIT: I also asked the maintainers directly - it turns out it will be un-deprecated in the next release: https://github.com/Imagick/imagick/issues/455
Not sure where you got that information, nor am I sure exactly how desperate you are, but if your JPEG is progressive/interlaced it will almost certainly contain a SOF2 marker of 0xff 0xc2. If it is not interlaced it will certainly not contain that.
See p32 here.
For testing, you can make a regular JPEG with ImageMagick in Terminal like this:
magick -size 64x64 xc:black regular.jpg
And an interlaced one like this:
magick -size 64x64 xc:black -interlace line interlaced.jpg
Related
I have a screenshot of the bank cheque, I need all the text from this screenshot but tesseract is unable to read it properly. I also tried to pre-process the image but the output fails miserably.
I am using ImageMagick for pre-processing and Tesseract for recognizing text.
The link to the image: https://imgur.com/a/pcgizic
I am able to retrieve the account number, but not IFSC code and person name "SRINIVAS"
The steps I am following is as follows:
magick -density 300 check1.jpg -depth 8 -strip -background white -alpha off check1.png
magick convert check1.png -resize 250% res_check1.png
convert -brightness-contrast 10x30 res_check1.png b_res_check1.png
convert b_res_check1.png -threshold 45% bin_res_check1.png
tesseract bin_res_check1.png o_res_check1
Note: I tried to resize the image upto 400% but it did not work.
Google Vision API is able to read and convert every single text properly.
In ImageMagick, you can use -lat (local area threshold) to process the image to clean the background. I also have a bash shell script, text cleaner, at http://www.fmwconcepts.com/imagemagick/index.php.
Input:
For ImageMagick 6, try
convert input.jpg -negate -lat 25x25+10% -negate result.png
Vary the -lat arguments to see if you can improve the results.
For ImageMagick 7, replace convert with magick.
Does that help? Small fonts are going to be hard to process. Enlarging a raster image, does not usually help much. But you can try with sharpening filters or sharper resize filters, such as -filter catrom. See http://www.imagemagick.org/Usage/filter/
You can also try doing a perspective transformation to rectify the original image before further processing. This might also help. See http://www.imagemagick.org/Usage/distorts/#perspective
I wonder if it's not possible to give ImageMagick a hint what type the input string (or file) is.
E. g. treat .sql as textfile.
I would need it to be used in php (Imagick).
The only thing I get is an exception that the file format is unknown:
no decode delegate for this image format `' # error/blob.c/BlobToImage/361
You can tell ImageMagick that a file contains text like this:
convert TEXT:stuff.sql result.png
which will give you an image of the contents of the text file stuff.sql.
So, if you want an image of a directory listing, you can do:
ls -l | convert TEXT:- listing.png
Or, if you have some SQL in a file commands.sql:
convert -background yellow -fill magenta text:commands.sql -trim result.png
Or, if you want it centred and with a larger border:
convert -background yellow -fill magenta text:commands.sql -trim \
-gravity center -extent 120%x120% result.png
As #MarkSetchell mentioned you can tell ImageMagick the (custom) filetype by prefixing it.
FILETYPE:FILEPATH
eg
TXT:/path/to/file.sql
I suppose you have to prefix a file format from specific list; identify -list format should give you that list of supported formats on linux
This works also with php: $im = new Imagick("txt:/path/to/file.sql");
Maybe someone knows how/if it works when having file contents as blob ($im->readImageBlob(...))
I am using ImageMagick to generate an image thumbnail, and i'm experiencing a weird problem. Weird because this has worked before and I dunno what changed to make it start failing.
Anyway, my commandline looks like this: (except that I've simplified the filenames)
convert -size 160x160 a1.jpg -thumbnail 144x144 -bordercolor #F00 -border 160-gravity center -crop 160x160+0+0 -repage -format jpg -quality 70 ./a2.jpg
What's happening is that the system is redirecting to a file named " -bordercolor"
Any ideas why this is happening and how to avoid?
On bash everything after the # will be considered part of a commment.
Maybe enclosuring the color with quotes
For a project I am running ImageMagick to convert several images (all of the same size 960x570) into a single PDF.
The command I'm running is:
convert *.jpg pdf/export.pdf
Since the images are all the same size I expect each PDF page to be equal in size but this is not the case as you can see in the screenshot below:
This is bit annoying since I don't know how I can force the size of each PDF page to be the same.
I tested the PDF on both an android device, ubuntu pdf reader and adobe reader and they all show the different sizes.
Thanks for helping!
EDIT1:
After testing out a few more things as suggested by Marc B and Basti I managed to put the same size on the JPG (uploaded) images.
The problem still persists with the images that are generated using webkit2png (Python script that converts a webpage/html file to an image). After trying (almost?) everything in the convert command I can't get these generated images to shop up properly in the PDF as you can see below:
Any help would be much appreciated!
I found the solution:
I needed to add the following options to convert the image saved from webkit2png:
-density 960x570 -units PixelsPerInch
I hope this helps other people out too in the future ;)
After a few seconds of using google, I found this:
-size <geometry> width and height of image
Example given by them:
$ convert -size 320x85 canvas:none -font Bookman-DemiItalic -pointsize 72 \
-draw "text 25,60 'Magick'" -channel RGBA -blur 0x6 -fill darkred -stroke magenta \
-draw "text 20,55 'Magick'" fuzzy-magick.png
http://www.imagemagick.org/script/convert.php
I would like to change the black border of this image :
http://dev.loungeup.net/im/
to transparent with Imagick in PHP.
The result image should have the gray border visible, the image inside the gray border visible, and everything outside the gray border (today in black) should be transparent and let the underlying content (in HTML page for example) visible.
I have been through the documentation several times and tried several solutions but did not figure out how to achieve it.
Any help is appreciated.
Thanks
Here's one method you could use which is similar to Photoshop's magic wand tool:
convert original.jpg -alpha set -channel alpha -fuzz 18% \
-fill none -floodfill +0+0 black transparent-border.png
Here are the commands broken down:
convert original.jpg: start Imagemagick with the original image
-alpha set: activate the alpha channel
-channel alpha: have subsequent operators act on alpha channel
-fuzz 18%: see -floodfill...
-fill none: see -floodfill...
-floodfill +0+0 black: start from the upper left corner (+0+0) and find neighboring pixels within -fuzz color distance of black and replace it will -fill
transparent-border.png: the output image
Here's the result:
Unfortunately, as you can see, this method still leaves some dark pixels with the image you provided because the border is not pure black and blends a bit with the inner gray border, and the image itself is quite small.
You will get much better results if you have a better-quality source image, or a larger one which you could then reduce in size after modifying.
If you're stuck with these small images (or if you just want to use another method), I would recommend going a different route where you create your own mask shape that is just smaller than the shape of the original photo, then add back your own gray border. I put together an example of this process below.
A possible command for this method would be:
convert original.jpg mask.png -compose CopyOpacity -composite \
-compose src-over new-border.png -composite clean-result.png
... broken down ...
convert original.jpg mask.png: start Imagemagick with original image and bring in mask.png as the second layer (mask.png is a white rounded-rectangle shape of the photo on a black background, but the shape is slightly smaller than that of the original - the result will remove the original's gray and black border).
-compose CopyOpacity -composite: use mask.png to "knock out" shape from original.png
-compose src-over: reset composite method to a simple overlay
new-border.png -composite: overlay a gray border (png is a 3 px wide border, 1px on each side of mask edge on a transparent background)
clean-result.png: the output image
I created mask.png and new-border.png in Photoshop. You could use Imagemagick's vector tools and do this all in one command using just original.jpg, but it wouldn't be easy.
The result of the above:
On a final note, I'm not sure whether you're using PHP's Imagick or the Imagemagick from the command line. Several years ago I tried using Imagick but quickly became frustrated from the lack of documentation compared to the command line (perhaps that's changed, though). Instead, I execute the commands from PHP (e.g., from exec() or passthru()). Some or many others will probably tell you that you should never execute shell commands from PHP, but as long as you carefully escape any arguments I have yet to see a convincing argument against doing so. Then you'll have the entire Imagemagick documentation at your disposal (http://www.imagemagick.org/Usage/).
Cheers.