I would like to zoom into an image test.png. That is, as a silly example, I would like to go from this
to this
The only way I was able to do it was with
convert -resize 110% test.png -gravity Center \
-crop 800x600+0+0 +repage 1.png
This is re-scaling the picture and then cropping it to its original size. The problem is that this only works because I already know that the original size of the image is 800x600.
How can I make this work without knowing the size of the image beforehand?
The way to do this, apparently, is with the -distort option:
convert -distort SRT '1.1 0' +repage test.png 2.png
where 1.1 is a 110% zoom and the 0 is a rotation angle.
Related
I'm using ImageMagick to trim some PDFs of text that I've converted to jpg for a project. In most cases it works well but when the page has just a small amount of text, say half a sentence, trim works too well so the image is just that, half a sentence.
It's a problem as it causes some display issues where I'm presenting it so it'd be helpful if there was a minimum image size. Is there a way of doing that in ImageMagick? Or adding padding to an image if it is converted below a certain size?
This is the command I'm using:
convert '*.jpeg' -fuzz 1% -trim +repage -set filename:base "%[basename]" "%[filename:base].jpg"
I'm using ImageMagick 7.1.0-19 Q16-HDRI arm 2021-12-22
Currently there is no way that I can think that would limit the trim in that way in Imagemagick. But you can automatically pad the image with some color such as white to some minimum size.
However, you will need to use "magick" in place of "convert" for Imagemagick 7 to make it work properly.
Input (256x256):
Lets pad it with white to 100x100 (minimum)
magick image.png -fuzz 1% -trim +repage -gravity center -bordercolor white -border "%[fx:w<100?round(0.5*(100-w)):0]x%[fx:h<100?round(0.5*(100-h)):0]" result.png
or better
magick input.png -fuzz 1% -trim +repage -gravity center -background white -extent "%[fx:w<100?100:w]x%[fx:h<100?100:h]" result.png
I had the exact same question recently, and the answer was to combine -trim and -extent.
convert -trim -background none -gravity center -extent 1024x1024 input.png output.webp
The image will first be trimmed, then extended to a given size.
You might want to change -gravity and -background depending on your use case.
I'm trying to crop an animated gif usind convert -crop. In some cases it's necessary to add more background to the image to fit. With other image formats it's done with
convert original.gif -rotate 0 -crop 1519x759-237-61\! -background white -flatten edited.gif
For gifs I tried
convert original.gif -coalesce -rotate 0 -crop 1519x759-237-61\! +repage edited.gif
convert is clipping/trimming the background and just the "subject" of the image is shown.
Example is here: https://imgur.com/ls1ED0Z
Result is here: https://imgur.com/59678cD
Expected Result is https://imgur.com/vZGaD7r
I added the red border to show how big the image is. Someone with a great solution? :)
Jan
To do what you want in Imagemagick, you should be using -extent rather than -crop in order to extend the size of the output.
Try this. Adjust the size and offset and background color as desired.
convert original.gif -coalesce -rotate 0 +repage -background white -extent 1519x759-237-61! -bordercolor red -border 3 result.gif
I have added a red border around the image.
With IM you can choose to "-crop", which is most often used to reduce the viewport dimensions, or "-extent", which can also be used to enlarge the viewport. It looks like there are a couple other issues with achieving the result in your sample image, but for starters, try simply substituting your "-crop" with "-extent" like this...
convert original.gif -coalesce -rotate 0 -extent 1519x759-237-61 +repage edited.gif
That will put your input image in a viewport of 1519x759, and place its upper left corner at 237 pixels from the left and 61 pixels from the top. You shouldn't need the exclamation point "!" in any case.
I've found this page on the imagemagick forum: Merging 2 gifs, one is animated and transparent which links to the imagemagick docs on Animation Modification; specifically, the example here:
convert canvas_prev.gif -coalesce \
-gravity NorthEast -draw 'image over 5,5 0,0 "rose:"' \
-layers Optimize draw_over.gif
Here's my attempt. I have these two gifs (i might be feeling a little morbid). The white in the first is actually transparent.
when I run
convert eyes.gif -coalesce -draw ' image over 0,0 0,0 "trump.gif" ' combine.gif
I get this:
which is not the complete effect I desire. The trump animation is no longer playing at all.
I want to see something more like this (this is created in Phaser JS, but this gives me no way to export the result as a new image other than manually recording a screencast):
One way to do it, yet not sure if it's the best, is as follows:
convert both animations into sprite-sheets of same dimensions
paste one image over the another
cut result into smaller frames and convert it into animated GIF
The commands should look like this:
montage -background none t.gif -tile x1# -geometry +0+0 tt.png
montage e.gif[0-16,0-9] -tile x1# -geometry +0+0 ee.png
magick convert -delay 10 -loop 0 ee.png tt.png -coalesce -flatten \
-crop 150x150 +repage output.gif
Tricky part is the second line with eyes image. It has only 17 frames while skull has 27. So the sprite sheet size must be adjusted.
I works, however I am not quite happy with this as solution requires manual entering of some parameters (frames selection and output image dimensions).
I have portrait and landscape JPEG images.
I want to make square thumbnails with white background from all of them. I need to keep the aspect ratio of all images and reduce the larger border to 200px.
I want to use ImageMagick (CLI) but I don't know how to do that. Any idea ?
Here is the individual images :
I think you need this:
convert -background white -gravity center \
input.jpg -resize 200x200 -extent 200x200 result.jpg
When an image is rotated by convert -rotate command the image size is enlarged. Is there a way to rotate around the center and to keep the image size, cropping the edges?
convert image.jpg -distort SRT -45 rotate_cropped_image.png
See http://www.imagemagick.org/Usage/warping/#animations
Example:
See also help on -distort: http://www.imagemagick.org/script/command-line-options.php?#distort
This seems now to simply "just work" -- for counter-clockwise 90 degrees:
$ convert image.jpg -rotate -90 rotated_ccw.jpg
If you know the size of the image the following works:
convert -rotate 45 -gravity center -crop NxN input output
tested with square images.
there may be a way to specify NxN is the input image size.
I've found this answer on Imagemagick forum:
A simple solution without knowing what the original size of the image
was, is to use the Alpha Composite Operator 'Src' as a 'crop to this
image size' type of operation. See:
http://www.cit.gu.edu.au/~anthony/graphics/imagick6/compose/#src
For example (ImageMagick version 6 only):
convert image.jpg \( +clone -background black -rotate -45 \) \
-gravity center -compose Src -composite rotate_cropped_image.png