I know it is possible to trim all transparency around image to make image smaller and contain only the image. But is it also possible to somehow know the location of "box", that contains the image?
For example I have 100x100 transparent image, which contains something at 10x10 box having topleft corner at x=15,y=15. Rest is all transparent.
I'd like to end up with 10x10 image, all transparency around trimmed, but also having that 15,15 information. Those are probably 2 separate actions. How do I do this in a script?
Just fyi - I am having bunch of images like this and they are layers, that I need to trim and stack onto eachother to make them clickable.
There are lots and lots of words but no image in your question so I am trying to guess what you want. I made this input image:
magick -size 100x100 xc:black -fill white -draw "rectangle 10,20 50,80" image.png
And I think you want to know the trim box, which is where it would trim to if you ran -trim:
magick image.png -format "%#" info:
41x61+10+20
So that's a 41x61 box with the top-left at (10,20).
Related
I am using ImageMagick to place an image on particular location on a white background canvas, can someone help me with it?
Here is what i tried so far, this would resize my image to correct resolution and put on a right size canvas.
Convert image.jpg -resize 1025x1537 -background white -extent 1920x1536
Now, I need to move it 40 pixles to the right , 20 to bottom
Reading the documentation for the geometry argument, it seems like one can use:
... -extent 1920x1536+40+20
If you want to define the offset from another origin, then you can use -gravity type.
https://imagemagick.org/script/command-line-processing.php#geometry
https://imagemagick.org/script/command-line-options.php#gravity
I have a JPG image with a known size of 3072x2048. Now I want to rotate that image by any degrees (e.g. 45), while keeping its original size. Thus - using ImageMagick on the command line - I first want to rotate, then crop the image, like this:
convert -rotate 45 -gravity center -crop 3072x2048 +repage original.jpg rotated-45.jpg
By using -gravity center I specify to crop the center part of the image, which is what I want. This operation produces four output images:
rotated-45-0.jpg
rotated-45-1.jpg
rotated-45-2.jpg
rotated-45-3.jpg
The first image rotated-45-0.jpg is exactly the final image I want to get. The other three I don't need. I could delete them, but I think it would be nicer to not generate these "extra" images in the first place. So I thought I could do it with this command instead:
convert -rotate 45 -gravity center -crop 3072x2048+0+0 +repage original.jpg rotated-45.jpg
This only produces one output image, however, now the top-left corner of the image is being cropped. So apparently the -gravity center is not used any longer.
Any ideas what I am missing here?
Using ImageMagick you can rotate an image any number of degrees while keeping the original canvas dimensions using "-distort SRT"...
convert original.jpg -virtual-pixel black -distort SRT 45 rotated-45.jpg
Use "-virtual-pixel" to specify how you want to handle the parts that were outside the canvas before the rotation. In this example I used "black". You can use black, white, background, tile, mirror, or none.
I have a image like below:
And I wanted to convert into something like below using imagemagick 6. How is that possible? I have gone through chop/shave/crop they all applicable to all sides symmetrically what I need is a partially chopped edges as below:
I have gone through https://www.imagemagick.org/Usage/crop/#chop but it helps to chop an entire edge/side but I need to remove edges partially.
You can achieve that by drawing a simple, white-filled polygon:
magick start.png -fill white -draw "polygon 0,0 60,0 60,16 16,16, 16,60 0,60" result.png
I want to crop an image into 2048x2048 slices like this:
convert big.jpg -crop 2048x2048 tile%04d.jpg
However, if the original is for example 5764x3888, the tiles end up like this:
2048x2048
2048x2048
1668x2048
2048x1840
2048x1840
1668x1840
How can I force each tile to be 2048x2048 and sit in the upper left corner?
I would prefer if I could do this in just a command line without a script, since I will do this on both Mac and Windows.
Or do I have to make the original image 6144x4096 first, so it's evenly divisible by 2048 and then crop it?
Thanks!
I would use this:
convert big.jpg -crop 2048x2048 -background blue -gravity northwest -extent 2048x2048 tile%04d.jpg
Obviously choose a different colour background to suit your needs, and choose a different -gravity to determine where the cropped image sits on its extended canvas.
I am composing an image from two input images - one with text and one background image.
When using the composite -blur option I get black areas to the right and to the bottom of the overlaying text. Example here:
This is my imagemagick command:
composite -blur 400 -geometry +16+193 example.png background.jpg result.png
I have tried the repage and trim commands to avoid the black areas but that did not work.
Does anyone have a good tip for me?