graphicsmagick draw rectangle - converting from imagemagick - imagemagick

I am trying to convert all my Imagemagick code over to GraphicsMagick to help speed up the process since we do about 5 a second. Just about everything worked just by changing out convert command to gm convert. But can't figure out why this one will not draw the rectangle.
gm convert /MYIMAGE.jpg \ -fill '#0007' -draw 'rectangle 0,342,508,392' \ -gravity North -pointsize \ 18 -fill white -annotate +0+350 'My Image Text Here' \ /MYIMAGE.jpg
I have been playing with it for hours and bee on their site all morning. Can't really see what the issue is. Like I said, every single of my other actions work perfect in GM. So not a issue with GM running, just something different from ImageMagick that im not seeing. Any help appreciated :)

I think your answer is here: http://www.graphicsmagick.org/api/draw.html#drawrectangle
Also changing your Imagemagick install from a 16bit one to a 8bit may improve speed as I belive that is one reason graphicsmagick is faster.
EDIT:
You need to specify all the relavent information when you ask a question.
Anyway why do you have all the backslashes in your code?

Related

Imagemagick - Getting the usable dimension of an image

I've a process which is creating a file with convert (ImageMagick) based on some parameter, and after that it checks the file and gives back the biggest dimension of it which has real pixels.
The commands look like this:
convert -size 5000x5000 xc:white -font {font} -pointsize {size} -fill black -draw "{some_occassional_additional_parameter}text 200,2500 \"{text}\"" {some_other_occassional_additional_parameter}{temporary_file}
convert {temporary_file}.png -trim +repage -format "%[w]x%[h]\n" info:
. It'll result something like: 526x425
This process runs half a million time per day, and it seems to be a huge bottleneck. I'm looking for a solution which can done this in memory, so not always creating a file and check it, but do it in memory somehow.
If can speed it up just like 50%, that'd be a huge achievement.
Thank You
Not at a computer to test, but change your first command to:
convert -size ... xc:... occasionalstuff -format "%#" info:
Note that you can, and probably should double quote the "%#" especially if you use expressions containing characters of significance to the shell, though it is not strictly necessary in this specific case.

Apply imagemagick transformation on only part of an image, whilst keeping the rest "stock"?

I have many documents per day that are photographed and I need to organise by QR code. The problem is, zbarimg is struggling to pick up many of the QR codes in the photos, so I have been trialling processing them with imagemagick first, using morphology open, thesholding, etc, which has yielded much better results.
The only issue with this is these apply to the whole image, which makes the rest of the file unusable for me, as I deal with the rest of the image based on colours and information which all gets destroyed in the processing. Could anybody give me an example on how I could apply my imagemagick filters to only a part of an image (coordinate based is fine) and leave the rest of the image untouched, so I can continue my process? I will be applying this to all images in a folder, so it's a batch file running this for me in most instances.
I have tried using crops, however this obviously leaves me with only the cropped portion of the image, which doesn't actually help when trying to process the rest of the file.
I'm running my scripts on Windows 11, if that means anything in terms of the solution.
Many thanks!
Tom
EDIT:
Thank you all for the advice given!
I solved my problem using the following:
convert a.jpg ( -clone 0 -fill white -colorize 100 -fill black -draw "polygon 500,300 500,1500 1300,1500 1300,300" -alpha off -write mpr:mask +delete ) -mask mpr:mask +repage -threshold 50% -morphology open square:4 +mask c.jpg
I did post this as an answer, but (and I have no idea why, I'm brand new to stack exchange) my answer was deleted. I used the clone to make the mask with the coordinates needed, then added the threshold and morphology that would make my QR codes more legible!
Thanks again everyone, really helped me out on my journey to figure it out :D
You can use -region to specify a region to process. So starting with this:
You can then specify a region to colorise with blue and then change the region to blur part of the blue and part of the original:
magick swirl.jpg -region 100x100+50+50 -fill blue -colorize 100% -region 100x100+100+100 -blur x20 result.png
The solution using -region may be the most direct. In ImageMagick versions where -region is not supported the same result can usually be achieved by cropping and modifying a clone inside parentheses.
magick swirl.jpg ( +clone -crop 100x100+50+50 -fill blue -colorize 50 ) -flatten result.png
The cloned, cropped, and and modified piece maintains its original geometry, so the -flatten operation puts it back where it was on the input image after the parentheses.

How to add Alpha -channels en masse with ImageMagick?

Suppose a dir with a lot of images, some of them miss the alpha-channel so looking bad against a background. I thought every picture had alpha -channel but some pictures now show white instead of having transparency. How can I add the alpha channels en masse?
Not Working
$ convert imageNoAlpha.png -alpha on imageAlpha.png
This will change white to transparent as in you coment BUT any other white in the image will be transparent as well:
convert input.jpg -background none -transparent white -flatten output.png
Thanks to Bonzo, I was able to get very cool results even without anti-alias! You can see the difference in the eyes with the below picture. I don't know how much you lose information by this but at least I am more able to adjust things, not so easy in anti-aliasing at least for me.
$ convert in.png -background none -fuzz 10% -transparent white -flatten out.png
En masse -approach is probably easiest with a bash -for-loop or use ImageMagick -pkg built for python. I don't know which approach is better, I will leave this here for future answers to improve. Thanks.

Pb with ImageMagick command

I'm trying to apply this code in my ".bat" file and my ASP.net projet:
convert checks.png -matte -virtual-pixel transparent -distort Perspective '0,0,0,0 0,90,0,90 90,0,90,25 90,90,90,65' checks_pers.png
The problem is that the result is like the original, no transformation to see, but i want to have a 3D Cover. I also tried many examples of the tutorial and they work only the distort Perspective?
I installed this version of ImageMagick : ImageMagick-6.7.2-0-Q16-windows-dll
(Answer pulled from OP's comment above)
In Windows we must use double quotes:
convert checks.png -matte -virtual-pixel transparent -distort Perspective "0,0,0,0 0,90,0,90 90,0,90,25 90,90,90,65" checks_pers.png

ImageMagick and Geometry Issue - resizing with >

using the latest version of imageMagick for windows (downloaded today)
small_image.jpg = 16x16
large_image.jpg = 800x600
convert small_image.jpg -gravity Center -resize '208x120>' -background white -extent 208x120 s_icon.gif
produces: "convert: invalid geometry `'208x120' # geometry.c/ParseRegionGeometry/1322" yet it still produces a 208x120 image with the tiny 16x16 image perfectly centered within the new image. Perfect.
However, if I try it with the larger image, it gives me the same error but it actually seems to crop rather than scale down as the "208x120>" implies.
What is that error, how do I fix it and why doesn't this command line work for larger images?
The documentation is less than stellar :(
I had the same issue. Apparently it's because you are using single quotes instead of double (normal) quotes. Your string should be like this:
convert small_image.jpg -gravity Center -resize "208x120>" -background white -extent 208x120 s_icon.gif
Don't know if this is allowed on *nix, since the documentation doesn't mention it...

Resources