Imagemagick destination name changes when squaring an image - imagemagick

I wrote a script to go through a source directory, resize the image to a square and save the results to a destination directory. It works fine except the name changes when saved in the destination directory.
Example:
source name: 111010xx1.jpg
stored in destination as: *-1.jpg
Here is the script:
for file in *.jpg; do
convert -background white -gravity center images/source/$file -resize 400x400 -extent 400x400 images/available/$file;
done
Any ideas as to why the name change?
Thanks

Related

ImageMagick - Overlay one image onto many

I have a folder of images labelled: test.png and img000.png-img480.png
How can I overlay test.png onto every imgxxx.png individually?
Currently "magick test.png img000.png -compose over -composite result.png" works for a single .png, and I'm not sure how/if mogrify can be used for all of them.
Any help is greatly appreciated (non-imagemagick solutions would also be great!) thanks :)
Make a copy of a few test files in a separate directory then change to that directory and try this:
magick mogrify -draw 'image Over 180,100 0,0 test.png' img*png
The 180,100 specifies where it will be drawn, and the 0,0 says to use the current size of test.png, i.e. no resizing. You can change the blend mode (i.e. Over here) for different effects. Get a list of available blend modes with:
magick identify -list compose
If you would like the results written in a different directory called RESULTS, use:
mkdir -p RESULTS
magick mogrify -path RESULTS -draw 'image SrcOver 180,100 0,0 test.png' img*png

ImageMagick: Mass extract alpha from png \ Combine files back

I can extract alpha from 1 file at time with this command
convert Alpha.png -alpha extract Alpha_alpha2.png
How to use it with .bat to mass extract all png in folder?
And what command would be to add alpha back to image?
You could use mogrify to extract the alpha channel from all images in a folder in Imagemagick.
mogrify -path path_to/new_folder -format png -alpha extract *.png
That would put all the alpha channels into an empty (but existing) new folder with the name of the input image
To add an alpha channel onto an image, one at a time, you would do:
convert image.png alpha.png -alpha off -compose copy_opacity -composite result.png

Imagemagick convert and compose batch of files

I am trying to make a fast convert of a batch of files like this:
convert ./src/*.png -set filename: '%t' -gravity West -draw 'image over 0,0 424,600 "./panel.png"' ./dest/%[filename:].png
which is pretty similar to COMPOSITE:
convert ./src/*.png ./panel.png -set filename: '%t' -gravity +0+0 -composite ./dest/%[filename:].png
except the last one is not working and just making one first crappy-looking file.
Looks like it's bug?
Does anybody know how to make it more correct with -composite?
for|awk|ls|find for each file in shell is not acceptable - because that is slower than the first example.
Read in the list of files,
set their output filenames,
include the IM special image placeholder "null:",
read in your overlay image,
optionally, set the geometry,
and composite that overlay onto all the other images with "-layers composite".
That null: separates the original input file list from the overlay image so ImageMagick knows where in the stack you want to start doing the composite.
Try something like this (one step per line for readability):
convert ./src/*.png \
-set filename: '%t' \
null: \
./panel.png \
-layers composite ./dest/%[filename:].png
You could use Imagemagick mogrify command. See http://www.imagemagick.org/Usage/basics/#mogrify and http://www.imagemagick.org/Usage/basics/#mogrify_compose
cd to input directory
mogrify -format png -path ./dest -gravity West -draw 'image over 0,0 424,600 "./panel.png"' *.png
Looks like it's bug?
Not a bug. Your second command is telling ImageMagick to consume all files matched into an image stack, and composite it as one.
You can attempt the same solution with the mogrify utility, but I believe it would be way simpler if you expand the bash script with a single for loop.
for f in $(ls src/*.png)
do
dest=$(basename $f);
convert "$f" ./panel.png -gravity West -composite "./dest/$dest"
done

How to add a watermark to all images in a folder using ImageMagik

I have been trying to find a way of watermarking all .jpg files in a given folder using ImageMagik directly from the terminal. I have searched a lot and I found the following:
composite -compose atop -gravity southeast -geometry +10+10 wm.png *.jpg
What I want to achieve is to add the watermark(wm.png) right under the bottom-right corner of each image and save the file under the same name. All images are different width but none is wider than 800px. So my watermark image is 800px wide. I want the watermark to be put right under the image, not over it and in the same time being cut to fit the size of the .jpg image.
The problem with the command above is that it s always outputting the following error:
composite: unable to open image `'tm.png'': No such file or directory # blob.c/OpenBlob/2480.
composite: missing an image filename `10.jpg' # composite.c/CompositeImageCommand/1593.
for i in *.jpg
do
composite -gravity southeast -geometry +10+10 wm.png "$i" "wm_$i"
done

Converting GIF's, PNG's and JPG's to .ICO files using Imagemagick

From: JPG, To: ICO;
/usr/bin/convert -resize x16 -gravity center -crop 16x16+0+0 input.jpg \
-transparent white -colors 256 output/favicon.ico
This is the output for the command line.
From: GIF's, PNG To: ICO;
/usr/bin/convert -resize x16 -gravity center -crop 16x16+0+0 input.png \
-flatten -colors 256 output/favicon.ico
I am having issues with transparency. I can't seem to get the right code for it, i have tried -channel alpha -negate, etc
This creates an image and when i apply to the site, it works with Firefox but none of the other browsers. IE, Chrome, Opera and Safari all hate it for some reason, it is a simple favicon.ico file. My conclusion is it must be my command somewhere is breaking. Please help?
Add this option to convert:
-background transparent
However, keep in mind that your original image must actually have an alpha channel. PNGs may have an alpha channel, JPEGs do not.
To convert PNG to ICO, setting the sizes you want, and preserving transparency:
(works for ImageMagick 7.0 or newer)
convert -background transparent "favicon.png" -define icon:auto-resize=16,24,32,48,64,72,96,128,256 "favicon.ico"
In this example, the ico file will have 9 entries: 16x16 px, 24x24 px, etc (assuming it is square)
Hint:
If you are on Windows 7, you can save the code below to a REG file and apply it to the registry. This will create an entry in the context menu of PNG files called "Convert to ICO". When you right-click file.png and select this command, file.png.ico will be generated in the same folder.
InstallConvertToIcoCtxMenu.reg
(remember to replace the ImageMagick path with the path where it is installed on your computer)
Windows Registry Editor Version 5.00
; Created with Default Programs Editor
; http://defaultprogramseditor.com/
; Edit Verb
[HKEY_CURRENT_USER\Software\Classes\pngfile\shell\ConvertToICO]
#="Convert to ICO"
[HKEY_CURRENT_USER\Software\Classes\pngfile\shell\ConvertToICO\command]
#="\"C:\\Program Files\\ImageMagick\\7.0.3-Q16\\convert.exe\" -background transparent \"%1\" -define icon:auto-resize=16,24,32,48,64,72,96,128,256 \"%1.ico\""
[HKEY_CURRENT_USER\Software\Classes\pngfile\shell\ConvertToICO]
"Icon"="C:\\Program Files\\ImageMagick\\7.0.3-Q16\\convert.exe,0"
One solution to the ICO problem would be not using it:
<link rel=icon href=/favicon.png>
Works in all browsers, and you get to use saner file format with better compression.

Resources