How to Append and batch process different logos with different images - image

I have list of images and logos and want to join them like appending it on middle while i have following details.
Images with name of files like image1.jpg, image2.jpg, image3.jpg, image4.jpg all of them are in size of 1024x876
Logo with name of files like logo1.png, logo2.png, logo3.png and so on all of them are in size of 1024x876
I want to join image1.jpg with logo1.png, in a way that i should got the transparent image as logo image contain empty background.
Instead of copying every logo and pasting on every images, how can i do this automation with script or any paid tool. Tnx

I would commend ImageMagick to you, it is available for free for Linux, macOS and Windows. Use v7.
The basic command you want is:
magick -gravity center background.jpg overlay.png -composite result.jpg
If you have lots of files to do, you will need a FOR loop. I don't really speak Windows BATCH, but it will look something like this:
#ECHO OFF
FOR /F "usebackq" %%i in (`DIR /B *.jpg`) DO (
ECHO magick -gravity center %%i %%~ni.png -composite result-%%i
)
Make a backup of your images and run this on a small sample copy. If it looks good, remove the ECHO and run again for real.

Related

How to resize images using ImageMagick? (mac os)

There is a pack of images and I want to reduce the height and width on 10 px of each image. The problem is that every image has a different size (i mean height and width). I found out how to resize images in terminal using ImageMagick, but it could resize images only to a fixed size (for example: convert example.png -resize 200x100 example.png). I need resizing to ((current width)-10px)x((current height)-10px) for every image. I am new to programming, be patient, please :)
If using Imagemagick 7, you can write a loop over all your images. In Unix syntax (assuming your images names have no spaces in them):
cd to your current directory
list=$(ls)
for img in $list; do
magick $img -resize "%[fx:w-10]x%[fx:h-10]" $img
done
If you do not want to overwrite your images, then create a new directory and put the path to that directory before the output.
If you want to do more than one image at a time, you can do:
cd to your current directory
magick * -resize "%[fx:s.w-10]x%[fx:s.h-10]" result.suffix
This will make the resulting images all with the same name, but with numbers appended, such as result-0.suffix, result-1.suffix, etc.
If you are using Imagemagick 6, then you will have to precompute the sizes in a separate command.
cd to your current directory
list=$(ls)
for img in $list; do
dimensions=$(convert image -format "%[fx:w-10]x%[fx:h-10]" info:)
convert $img -resize $dimensions $img
done
Note that resizing will not necessarily give you the result you want, since Imagemagick will try to keep the aspect ratio. So if you want to force the exact sizes, then you need to add ! to your resize argument. However, that will cause some distortion, though probably not too much for only resizing by 10 pixels.
An easier way would be to just shave off 5 pixels all around. Then you could do a whole folder using mogrify:
cd to current directory after creating a new directory for the output if desired:
mogrify -path path/to/new_directory -shave 5x6 *
In Imagemagick 7, that would be magick mogrify ...

Use ImageMagick montage with a file name substring variable

I have only very rudimentary programming and command line skills, hence I'm a bit stumped by the following.
I have a directory with image files like this:
abc_B.jpg
abc_G.jpg
abc_R.jpg
abc_RGB.jpg
defg_B.jpg
defg_G.jpg
defg_R.jpg
defg_RGB.jpg
etc...
I want to stitch together sets of the four R, G, B, and RGB images using ImageMagick. For an individual set of images this is pretty straightforward:
montage *_B.jpg *_G.jpg *_R.jpg *_RGB.jpg [some arguments] montage.jpg
In fact, I've been copying sets of four images into a temp directory and run the above command. But this is of course not very efficient or practical with larger sets of images. But to run it on the entire directory there needs to be a way to take the 'abc', 'defg', etc. part of the file name and put it into a variable (let's call it %v) and run something like this:
montage %v_B.jpg %v_G.jpg %v_R.jpg %v_RGB.jpg [some arguments] %v_montage.jpg
Now, to iterate over files in a directory there's the FOR command. But I have no idea how to handle that with groups of four files and how to extract and use a filename substring to make that work.
Some help would be greatly appreciated.
It might look something like this - store it as GO.BAT:
#ECHO OFF
FOR /F "delims=_" %%G IN ('DIR /B *_R.JPG') DO (
ECHO MONTAGE %%G_R.JPG %%G_G.JPG %%G_B.JPG %%G_RGB.JPG ... montage_%%G.JPG
)
Sample Output
MONTAGE abc_R.JPG abc_G.JPG abc_B.JPG abc_RGB.JPG ... montage_abc.JPG
MONTAGE defg_R.JPG defg_G.JPG defg_B.JPG defg_RGB.JPG ... montage_defg.JPG
You would remove the ECHO if you like what it does, because at the moment it does nothing except tell you what it would do!
I use DIR /B in the command to avoid getting headers, and I only list the *_R.JPG so that each filename stem only occurs once - not four times.
There's a handy reference here.

Concatenating multiple pbm files, cmd

So we have, let's say, 10 files, called 01.pbm, 02.pbm, 03.pbm, etc. Using cmd with commands like paste or clip (or of course any you know) how could you merge all 10 of them keeping the corresponding file size? (if each of them is 1kb, the output should be 10kb). Keep in mind I use windows... (ugh, I know)
Use ImageMagick v6 to accomplish the task.
To append (merge) left-to-right:
convert *.pbm +append lr_out.pbm
To append top-to-bottom:
convert *.pbm -append tb_out.pbm
For more information read the documentation
Update
As fmw42 pointed out for IM v7 then the syntax should be:
magick *.pbm +append lr_out.pbm
magick *.pbm -append tb_out.pbm
So at the end it's just the simple function "type"...

How to crop 486 pixels from the bottom of each JPG image in the folder with ImageMagick?

How to crop 486 pixels from the bottom of each JPG image in the folder with ImageMagick?
The following command
magick -crop -0-486 *.jpg
says
magick.EXE: no images found for operation `-crop' at CLI arg 1 # error/operation.c/CLIOption/524
magick.EXE: no image to apply a property "%w" # warning/property.c/GetMagickPropertyLetter/2561.
magick.EXE: unknown image property "%w" # warning/property.c/InterpretImageProperties/3499.
magick.EXE: no image to apply a property "%h" # warning/property.c/GetMagickPropertyLetter/2449.
magick.EXE: unknown image property "%h" # warning/property.c/InterpretImageProperties/3499.
magick.EXE: no image to apply a property "%m" # warning/property.c/GetMagickPropertyLetter/2480.
magick.EXE: unknown image property "%m" # warning/property.c/InterpretImageProperties/3499.
Please, give specific example, internet in controversal (various names like mogrify, convert, various commands etc). Also don't point to ImageMagick "Talmud". Need just a simple example.
OS is Windows, Magick is installed with Chocolatey.
Please make a backup of your images before using the following commands.
The command for a single image is convert or if you have ImageMagick 7+, it is magick.
The command for multiple images is mogrify, or if you have ImageMagick 7+, it is magick mogrify.
The command you want is as follows and it will chop 486 pixels off the bottom of each image in the current directory:
magick mogrify -gravity south -chop x486 *.jpg
The main ImageMagick command command used to be called convert but there is a Microsoft tool with the same name that has caused confusion for years, so all the ImageMagick commands were prefixed with magick, followed by the old name. So,
animate ...
becomes:
magick animate ...
And
mogrify ...
becomes:
magick mogrify ...
In the case of convert, which is the most common usage, you can now use
magick convert ...
or simply
magick ...
where convert is implied.

Batch convert/resize different image formats to JPEG of certain resolution with ImageMagick

How do I use mogrify to batch-convert a ton of files (.TIF, .EPS, .JPG but most annoyingly of all-) .PSD files and only keep their first layer?
I found a solution on how to convert all images, but I kept getting filenames in my output-directory which were different from my originals (they had -0, -1, -2 etc. attached to the original filename).
I have 2 folders, ./original/ (which contains my PSDs, EPS, TIF, GIF, JPGs and other images) + the folder ./converted/ (which is the target folder for my conversion)
The command I use to convert my images are:
mogrify -verbose -path ./converted/ \
-alpha off -strip -mattecolor white -background white \
-resize 512x512 -format jpg -quality 75% -interlace Plane ./original/*.*
But no matter what I try, I keep getting this garbage which mangles my filenames. There is one mode however which just merges every interpretation of the files into one, but that's also quite useless as I am getting black backgrounds on my transparent files.
After 2 hours of searching I finally found the answer, and since I love stackoverflow, I'm sharing it here:
In order to select the best image of PSD's or first frame of .GIF's, all you need to add is an index of 0 (litterally, without the double quotes: "[0]") to the input file.
So the command to convert all images (you need to install ImageMagick with mogrify first), with a white background for anything transparant, within a bounding box of 512x512 pixels, outputted at jpg with 50% compression quality, the layers Disposed and the first index used, you need to execute the following command:
mogrify -verbose -path ./converted/ \
-alpha off -strip -mattecolor white -background white -layers Dispose \
-resize 512x512 -format jpg -quality 75% -interlace Plane ./original/*.*[0]
Hopefully this will serve as an easy to use template for anyone who needs to batch convert a lot of images.
I found several image converters but none were as easy to use as mogrify, and of course, it being a linux executable, it gives near infinite possibilities about what you can do with it... everything should be scriptable.

Resources