To average together multiple images, globbing works fine:
magick convert -average *.png out.png
But how would I specify several input images on Windows command line, without using globbing? (Ultimate goal is to make a batch file so I can select multiple images, then combine them using SendTo menu, for which %* will receive "C:\...filename.png" "C:\...file2.png" "C:\...something.png".)
There are several options...
Option 1
You can just enumerate the files on the command line:
magick fred.png bill.png tina.png -average result.png
I haven't tried this, but from your question, the following should work as it is directly equivalent to the example above:
magick %* -average result.png
Option 2
You can write the filenames in a file and pass its name, so if filelist.txt contains:
image1.png
image2.png
image3.png
Then run:
magick #filelist.txt -average result.png
Option 3
You can send the list of filenames to ImageMagick on its stdin:
echo -e "file1.png\nfile2.png\file3.png" | magick #- -average result.png
Not sure how you do a newline in BATCH - but the \n above are newlines!
Maybe it is:
( echo file1.png & echo file2.png & echo file3.png ) | magick #- -average result.png
The convert is actually implicitly assumed since v7 - you only need specify the legacy command if you do magick identify ... or magick mogrify ... or magick compose ... etc.
Related
I am trying to automate the converting images to specified tif formats. I have it converting just fine, but am also needing to add "_GS" at the end of the file name and before the extension to each file converted. Below is what I have but have had no luck finding a solution to add "_GS" to the file name. Thanks in advance for any help.
for f in "$#"
do
echo "$f"
/usr/local/bin/mogrify -density 300 -resize 1000x1000 -type grayscale -define tiff:endian=msb -compress LZW -format tif "$f" [0]
done
Item 1: With Image Magick, to create a new file instead of overwriting an existing one, use convert, not mogrify (magick convert with newer versions of IM).
Item 2: You can use shell parameter expansion to remove the extension, and then build the new filename from that and the new suffix:
for f in "$#"
do
echo "$f"
/usr/local/bin/convert "$f" -density 300 -resize 1000x1000 -type grayscale \
-define tiff:endian=msb -compress LZW -format tif "${f%.*}_GS.tiff"
done
${variable%pattern} returns the expansion of variable with the shortest match of pattern removed from the end.
I am trying to convert an entire folder to grayscale, using image magick.
convert *.jpg -colorspace Gray -separate -average
is met with this error :
convert: `-average' # error/convert.c/ConvertImageCommand/3290.
What is the correct command for this?
If you have lots of files to process, use mogrify:
magick mogrify -colorspace gray *.jpg
If you have tens of thousands of images and a multi-core CPU, you can get them all done in parallel with GNU Parallel:
parallel -X magick mogrify -colorspace gray ::: *.jpg
Also, the following can be used in a script - for the context menu of file managers like Dolphin, Nautilus, Nemo, Thunar etc:
for filename in "${#}"; do
name="${filename%.*}"
ext="${filename##*.}"
cp "$filename" "$name"-grayscale."$ext"
mogrify -colorspace gray "$name"-grayscale."$ext"
rm "$name"-grayscale."$ext"~
done
In my folder i have 4 pics every time in a 4X6 pic size.
In next step i want to show all the 4 pic's into different cobinations to user like, {pics: 1 2 3 4}
image 1: 1+2;
image2: 1+2+3;
image3: 2;
image4: 1+2+3+4;
how do i can achive this...in .net/any technology please suggest.
You can do it like this with ImageMagick which is installed on most Linux distros and is available for OSX, and Windows. At the command-line, in Terminal, side by side:
convert a.png b.png +append result.png
Or, above and below:
convert a.png b.png -append result.png
Or, 4-up:
convert a.png b.png +append \( c.png d.png +append \) -append result.png
Or 4-across:
convert a.png b.png c.png d.png +append result.png
If your images are JPEG, just change the extensions. If you are on Windows, you may need to put carets (^) in front of the \ or ( to escape them.
In here I found a piece of code that finds and resizes all images within a folder with applescript
Now I need to apply a stamp to those images one by one. I already have a transparent jpg prepared with the same size and ready to be pasted on all of them.
I just lack the knowledge to do it on terminal so I could mix it with applescript.
Does anyone know how to do this without making a workflow? Because it takes a lot of time and keeps the laptop busy
Updated Again :-)
You can get the height of an image like this:
identify -format "%h" image.jpg
500
and the width like this:
identify -format "%w" image.jpg
800
If you want to find the lesser of the height and the width, and then take 10% of that for your logo size and make it integer, you would do:
identify -format "%[fx:int(0.1*min(h,w))]" image.jpg
50
If you want to put that in a variable, you would do
logosize=$(identify -format "%[fx:int(0.1*min(h,w))]" image.jpg)
echo $logosize
50
You could then use that in the original command below like this:
convert image.jpg -gravity southeast \
\( copyright.png -resize "${logosize}x${logosize} \) \
-composite result.jpg
I suspect you are going to want to run that with the find command, aren't you? :-)
find . -iname \*.jpg -exec bash -c 'echo Processing {};logosize=$(identify -format "%[fx:int(0.1*min(h,w))]" "{}"); echo $logosize;convert "{}" -gravity southeast \( copyright.png -resize "$logosizex$logosize" \) -composite "{}"' \;
Updated Answer
If you want to resize your original image before compositing the logo unchanged on top, use a command like this:
convert image.jpg -resize 2000x1000 -gravity southeast copyright.png -composite result.jpg
If you want to resize the logo before compositing it on top of the unchanged original image, use a command like this:
convert image.jpg -gravity southeast \( copyright.png -resize 700x200! \) -composite result.jpg
Original Answer
I would use ImageMagick. It is extremely powerful and simple to install if you use homebrew. Ask if you don't know how...
Let's assume you have an image called image.jpg and a transparent logo/copyright called copyright.png.
image.jpg
copyright.png
Then the command to do a single image would be:
convert image.jpg copyright.png -composite result.jpg
If your logo/copyright and image are different sizes, and you want to force the logo to, say, the bottom right corner, just set the -gravity accordingly like this:
convert image.jpg -gravity southeast copyright.png -composite result.jpg
If you wanted to do all the JPEGs in the folder, you would need a loop:
#!/bin/bash
shopt -s nullglob
shopt -s nocaseglob
for f in *.jpg; do
convert "$f" copyright.png -composite "$f"
done
By the way, you cannot have a transparent JPEG - that format doesn't support transparency.
If you are really intent on using Applescript - I don't know why anyone would be - you can call the above using do shell script - make the file executable first. Ask if unsure how.
If you want to recurse down into all directories (folders) starting at the one you are currently located in and add the logo/copyright to all images, I would make a copy of them somewhere else first and do a trial run. The command would be:
find . -iname "*.jpg" -exec convert "{}" copyright.png -composite "{}" \;
That says... "find, starting at the current directory (.), disregarding upper/lower case (-iname), all files ending in "JPG", and apply the logo/copyright to them, resaving on top of the original file".
I had same issue years ago, and the only way I found is an Applescript using Photoshop (duplicate layer containing the logo on the photo and flatten file).
the script loops to all file of a folder.
... but you need Photoshop for this script !
I can share that script if it helps
Current image folder path:
public_html/images/thumbs
Output image folder path:
public_html/images/new-thumbs
I have 10 video thumbs per video in current folder, named of image thumbs:
1-1.jpg
1-2.jpg
1-3.jpg
1-4.jpg
1-5.jpg (Resize)
1-6.jpg
1-7.jpg
1-8.jpg
1-9.jpg
1-10.jpg
2-1.jpg
2-2.jpg
2-3.jpg
2-4.jpg
2-5.jpg (Resize)
2-6.jpg
2-7.jpg
2-8.jpg
2-9.jpg
2-10.jpg
I want to resize all 5th images(*-5.jpg) to the new folder. I've tried below command but no luck:
mogrify
-path
public_html/images/thumbs/*-5.jpg
-resize 16×12
-quality 100
public_html/images/new-thumbs/*-5.jpg
"Mogrify" should be called from the directory with the original thumbnails, while the -path parameter is for pointing target directory.
mkdir public_html/images/new-thumbs
cd public_html/images/thumbs
magick mogrify -resize 16x12 -quality 100 -path ../new-thumbs *.jpg
http://www.imagemagick.org/Usage/basics/#mogrify
The last arguments are the list of files, so you can filter by name 1-*.jpg for example.
Suggested solutions do not work properly on the latest ImageMagick (at least, on macOS).
Command, that works overwriting source images is as follows:
magick mogrify -path ./ -resize 50% -quality 80 *.jpg
To avoid overwriting the original images, write to a new folder:
magick mogrify -path path/to/destination/folder/ -resize 50% -quality 80 *.jpg
In ImageMagick 7 versions its built into the magick ...so..
magick mogrify -resize 16x12 -quality 100 -path ../new-thumbs *.jpg
Make sure that the folder you specify in path exists. It will not be created by ImageMagick.
Find more information here https://www.imagemagick.org/script/mogrify.php
For those having Shotwell installed on Ubuntu/Debian, following may be more easy to export selected images in a folder to another folder through processing the images as needed.
Open Shotwell
Select the images you want to export
File > Export
Adjust the values to your needs
Select the folder to export