So, I have this background image:
And I have a 1px x 1px image that I want to overlay on that. If I run:
convert bg.png \( -size 80x240 -background none -rotate 30 -geometry +120+88 tile:red.png \) -composite result.png
I get this:
But I want to rotate it with fixed center. The expected result should be something like this:
Do you know how can I accomplish that?
Thank you.
Looking into the comment by #frostyterrier I think his problem is he needs +distort and is using -distort?
This page should help: http://www.imagemagick.org/Usage/distorts/#srt
Rotate an image and have a transparent background
convert input.jpg -background none -virtual-pixel background +distort ScaleRotateTranslate 30 output.png
Related
Friends,
I need to -trim some images but keep the original canvas size. Works like this:
convert in.png -fuzz 10% -trim -background white -set page "%[fx:w]x%[fx:h]" +repage out.png
But how can I position the trimmed image part at it's original position? -gravitiy center is not an option as the to-be-trimmed part usually not at the canvas center.
Any ideas?
You should be able to -trim an image, then use -flatten to lay it back onto its original canvas. Try this command...
convert logo: -background none -trim -flatten trimmed.png
#GeeMack's answer is certainly simpler and more succinct, but if you need more flexibility for dinking around, another way is to get the image height and width and the trimbox in one invocation and use them in the next - maybe with adaptation.
So, starting with this image:
# Get image width and height and the trim-box
read geom trim < <(magick start.png -format "%G %#" info:)
# Make a new white canvas same size as original and trim new image onto it
magick -size $geom xc:white \( start.png -crop $trim \) -flatten result.png
I put an artificial yellow border around it so you can see the extent of it on SO's white background.
I am using imagemagick to convert files and reposition them, i have a 4 * 6 png which i need to position on a letter canvas on the top half of the page.
I have the below command which i am using, but its confusing. can anyone suggest how i can achieve what i want.
this is what i have tried, can any one guide me on this.
convert -rotate -270 -page Letter me-9370120111400937899958.png on-9370120111400937899958.pdf
I have also tried this, but the overlayed image is not moving and is stuck to the bottom
%x{convert -page Letter -rotate -270 "/var/folders/rp/rk2q4l7j4ds_w37vwvgx46tr0000gn/T/a8.png" -geometry +50+50 "/var/folders/rp/rk2q4l7j4ds_w37vwvgx46tr0000gn/T/a8.pdf"}
I have tried reading on this link http://www.imagemagick.org/script/command-line-processing.php#geometry but could not figure out.
Updated Answer
It occurred to me later that you may have meant this:
convert -page letter -gravity north \( a.jpg -background yellow -splice 0x10 \) a.pdf
Obviously change yellow to none and increase the 0x10 to 0x20 to move further down the page, and add -rotate 90 before the splice maybe.
Original Answer
Not sure exactly what you mean, but I think this will get you started. Let's try some options. I will make the canvas yellow so you can see it and the file you want to position on top will be red.
So let's try some options...
First, let's move the image across to the right by zero pixels and down from the top-left by 40 pixels - the default position (or gravity) is NorthWest so we are positioning relative to that.
convert -size 612x792 xc:yellow a.jpg -geometry +0+40 -composite result.jpg
If you want the image centred, use -gravity north and position relative to that - a little closer to the edge this time maybe:
convert -size 612x792 xc:yellow -gravity north a.jpg -geometry +0+10 -composite result.jpg
If you want the background rotated:
convert -size 792x612 xc:yellow -gravity north a.jpg -geometry +0+40 -composite result.jpg
If you want just the overlay rotated, do that in "aside processing":
convert -size 612x792 xc:yellow -gravity north \( a.jpg -rotate 90 \) -geometry +0+40 -composite result.jpg
If you want the canvas white, change yellow to white. If you want the canvas transparent, change yellow to none.
After I rotate or deskew an image with Imagemagick there's a white background in the corners, where the rotation took place. Example:
convert image.png -rotate 10 out.png
Output: http://imgur.com/8bZQ6
Is there a way I could somehow fill up those white corners with some texture or at least a color that blends in with the image? Cropping is not an option.
I've found this great solution for simple rotation:
convert image.png -virtual-pixel Edge +distort SRT 10 out.png
Output: http://imgur.com/edMS0
But unfortunately it doesn't work with the -deskew command...
So, does anyone know how to fill up those corners in a similar way for the -deskew (and -rotate) command? The point is to mask the fact the image was rotated as best as possible.
I'll go ahead and answer my own question, but I'm still hoping for a better solution.
You can set the -background color, which works with rotate and deskew.
Here's a solution that uses the average image color:
convert image.png -background `convert image.png -resize 1x1 txt:- | tail -1 | cut -b 30-50` -rotate 10 out.png
Output: http://imgur.com/YCqkC
And a better solution that takes some border pixels:
convert image.png -background `convert image.png -resize 100x1! \( +clone -crop 1x1+0+0 \) +append -crop 2x1+99+0 -resize 1x1 txt:- | tail -1 | cut -b 30-50` -rotate 10 out.png
Output: http://imgur.com/4wDPO
There's some bash scripting (inside the backticks), so these solutions are unix only.
Try this:
convert image.png -background transparent -rotate 10 out.png
I am using this command for imagemagick to extend the size of an image and background to white
convert input.png -extent 495X320 -gravity center -background white output.jpg
The size is doing extent but the background is black every time. I tried many methods but the same black is coming every time.So can some one help me how to solve this. Any help and suggestions will be highly appreciable.
The order is important here, use -background before -extent:
convert input.png -background white -extent 495X320 -gravity center output.jpg
Leaving this for people that have tried the other answer but it still does not work.
In my case I needed
convert image.png -resize 80% -quality 80% -background white image-edited.jpg
Add the -flatten option at the end and it should work. So like:
convert image.jpg -resize 80% -quality 80% -background white -flatten image-edited.jpg
Getting started with ImageMagic and trying to find a way to do this... If an image is less than 50 pixels tall or 50 pixels wide, I'd like to place it (un-scaled) in the horizontal/vertical center of a new 50x50 pixel canvas on top of a white background - and save that as the new image. Anyone know if this is possible with ImageMagick? Thanks!
I used -extent to do this:
convert input.jpg -gravity center -background white -extent 50x50 output.jpg
I wanted to do the same, except shrink the image to 70% inside. I used this:
convert input.png -resize 70%x70% -gravity center -background transparent -extent 72x72 output.png
Not exactly what was requested but hopefully it will help someone ;).
I have once used this code to place an image in the center of a new canvas with white background. hope this will help you
convert -background white -gravity center your_image.jpg -extent 50x50 new_image.jpg
See cutting and bordering for a huge number of examples. Here's one simple way you might do it:
convert input.png -bordercolor Black -border 5x5 output.png
Of course, you'll need to calculate the size of the border to add (if any) based on the dimensions of the input image. Are you using an ImageMagick API, or just the command line tools?
I tried this:
convert test.jpg -resize 100x100 -background black -gravity center -extent 100x100 output.png
You can use single composition to do this. So it would look something like this:
convert -size 50x50 xc:white null: ( my_image.png -coalesce ) -gravity Center -layers Composite -layers Optimize output.png
To modify the source image you need to use mogrify:
mogrify -gravity center -background white -extent 50x50 source.jpg
If an image is less than 50 pixels tall or 50 pixels wide
In my case, the images were much larger than the destination canvas, and weren't square. So I resize them proportionally to fit inside. Example:
convert in.png -resize 46x46 -background none -gravity center -extent 50x50 out.png
The 46x46 limit ensures a 2 pixel margin minimum. Note that the above does not distort the image, e.g. a rectangle does not become a square.
I used background none for a transparent background, but you can choose a solid color instead.