how to use convert to center an 512x512 jpg onto a blank 1024x500 image? - imagemagick-convert

I have a 512x512 jpeg file, but I need a 1024x500 image jpegfile. I thought I could do something use convert like this:
convert my512x512.jpg -page "1024x500" my1024x500.jpg
But when I open my1024x500.jpg it is still 512x512. I have also tried ...
convert my512x512.jpg -resize "1024x500!" my1024x500.jpg
... but that distorts the image. How can I center my 512x512 in a 1024x500 jpeg file?

Ah! I figured it out.
convert my512x512.jpg -background none -gravity center -extent '1024x500!' my1024x500.jpg

Related

Merge an animated gif over a static png at a specific location using ImageMagick

I have managed to paste an animated gif over a static png and obtained an animated gif from
those sources with the following command.
convert canvas.png animation.gif test.gif
and it works, but the animation and the canvas share the upper left corner, which is not what I want.
By reading a little I discovered that I have to use either the -composite option or the command, but I have not found examples of the right syntax to use.
I tried this:
convert canvas.png animation.gif -geometry +780+275 -composite test01.gif
which gives a static image with just the first frame of animation.gif
I tried other syntax but just produces errors.
What is the right way to accommodate the animation?
Try the following in Imagemagick. It takes a special null: operator to separate the two images and -layer composite. Also you must use -page or -set page rather than -geometry when using -layers composite. The following is Unix syntax. For Windows, remove the \ before the parentheses.
convert canvas.png null: \( animation.gif -coalese -set page +780+275 \) -layers composite -layers optimize test01.gif

Copyright/Watermark many images with different resolutions (with ImageMagick)

i am trying to solve the following problem:
I have one picture logo.png with a resolution of 1260x1580. I want to use this to copyright different JPG-Images, e.g. image1.jpg with a resolution of 1280x853. I want to have the logo e.g. at the bottom right and always with a height of e.g. 1/8 of the height of the JPG-Image.
Short: I have many images with different resolutions and the copyright should have always the same proportion (e.g. 1/8 of the total heigth) within that image.
I am using ImageMagick on command-line (on Windows 10), at the moment like this:
magick image1.jpg logo.png -resize x%[fx:u.h/8] -gravity SouthEast -geometry +15+15 -composite outfile.jpg
Unfortunately the resize-Option with x%[fx:u.h/8] doesn't work like expected, it also resizes the JPG-Image image1.jpg. I don't know, how i can manage it to resize only the logo.png and let the size of image1.jpg untouched. When i put ( logo.png -resize x%[fx:u.h/4] ) in brackets of course u.h then refers to logo.png, this is also wrong :-/
It would be great if you can assist me a little bit to find the right command for my purpose... Thanks for your replies and help!
PS: I hope that i didn't ignored some important source or help, but i can't find the solution by myself - sorry.
You have a stack of two images, the main input and the logo. You can have your "-resize" operation work on just the logo by adding a condition to the FX expression. Start your command with something like this...
magick image1.jpg logo.png -resize x%[fx:t==1?u[0].h/8:u[0].h] ...
The expression runs once for each image in the stack. The "t" substitutes for the position of the image in the stack, the first image is 0, the second is 1. So if "t" equals 1, it's the logo. Resize it to 1/8 the height of the first image indicated by "u[0].h/8". Otherwise resize it to "u[0].h", which is already the height of the first image, so it won't change that one.
In Imagemagick, try simply using parenthesis to limit the operation
magick image1.jpg ( logo.png -resize x%[fx:u.h/8] ) -gravity SouthEast -geometry +15+15 -composite outfile.jpg

How to Join images of different size - adding Footer Image to all images (BULK)

I have more than 8000 images of different dimensions.
I want my footer image to adjust its width according to each image size and join the image at the bottom.
I am a basic person and will not be able to program it myself.
Is there any software that will help me do this?
You could use ImageMagick, which is installed on most Linux distros and available for OS X, all good OSes and Windows from here.
So, if you have an image like this:
the code to add a label would be pretty easy like this:
convert image.jpg -gravity center -background lime -fill yellow -stroke black -pointsize 36 label:"My Photo" -append result.jpg
I am not suggesting that is a good colour scheme, I am just showing you how/where to set the colours, and you can change them as you wish. If you now run the same code on a different size image like this:
you will get this:
There are countless examples here.
Please copy some of your images to a test folder and practice with the code below in there so you don't mess up your original photos. As I said, I don't really "do" Windows, but the code will look like this to do all the PNG and JPG files in a directory:
for %a in (*.PNG *.JPG) do convert "%a" -gravity center -background lime -fill yellow -stroke black -pointsize 36 label:"My Photo" -append "%a"
There are some good examples of using FOR loops here.
You can try Irfanview it has the paste special option that will resize and paste your footer image below the original one in one shot. But unfortunately it can't do it for you for the 8000 images.
To resize + merge a footer: Open your footer image, copy it (ctrl+c)
Now open your original image in IrfanView, go to Edit -> Paste Special -> to Bottom, it will resize & merge your footer under the original image.
IrfanView has also a batch conversion option to resize images in bulk but it can't join your images automatically. So it will help you with the resizing if needed.
To open the batch conversion in IrfanView, go to File -> Batch conversion/rename -> Advanced
From here you have tons of stuff to do among which the batch resize

Add an image as a background to a previously manipulated image with Imagemagick

I'm writing a script that:
Scales
Crops
Adds a background image
to a series of around 400 transparent PNGs. I'd like to make this run as fast as possible.
Currently I've got it as two separate commands:
convert $input.png -scale $scale% -gravity Center -crop 640x640+0+0 +repage $output.png
composite -gravity center $output.png $background $output.png
Is there a way to reduce this to a single command? I've been looking at the docs for -composite but I can't see a way to add an image as the background after doing the other manipulation.
Any ideas? Thanks
Why don't you just use a && between the two commands? The second command will get executed when the furst exits without an error... Should work...

Combining 2 png in one with convert

I am using convert from ImageMagick to combine 2 png in one using this script :
convert background.png logo.png -layers merge final_background.png
It is working but I would like to move the logo at 20 pixels from the top, is it possible ?
Thanks a lot
Thierry
I found how to do this :
convert background.png -page +0+130 stationLogo.png -page +0+440 -layers merge Default.png

Resources