I want to combine 1.png and 2.png
When I combine the two files, I want to change the height of 2.png to the height of 1.png
I used the append command, but I didn't get the result I wanted.
Below is the command I used.
convert +append 1.png 2.png result.png
Please teach me the way!! Thanks !
image
In Imagemagick 6, you would need to get the height of image 1 first in a separate command. For example on a Unix-based system:
ht=`convert image1.png -format "%h" info:`
convert image1.png \( image2.png -resize x${ht} \) +append result.png
In Imagemagick 7, you can do it all in one command line:
magick image1.png -set option:ht "%ht" \( image2.png -resize "x%[ht]" +append result.png
Example:
Input
ht=`convert monet2.jpg -format "%h" info:`
convert monet2.jpg \( zelda1.jpg -resize x${ht} \) +append result.png
Result:
convert -append img1.png img2.png result.png
Related
Is there any way to resize an image (jpg/ jpeg)on a range of predefined sizes and export at once on Gimp? (same image-different sizes batch scale and batch export).
Thank you!
From the Gimp GUI, there is a script/plug-in for this, see ofn-export-sizes here(*).
If you want to do that in batch, it is a lot easier/faster to use ImageMagick, which is designed to be used from a shell script:
magick convert input.jpg -resize 500x output-500px.jpg
(here 500x means resize to 500px wide and keep aspect ratio, you can otherwise set
height, width or both). You can even apply a bit of sharpening to compensate for the blur:
magick convert input.jpg -resize 500x -sharpen 0x1.0 output-500px.jpg
For more info, there is a rather active stream of ImageMagick questions here on SO.
(*) Note that in Gimp, a script usable in batch doesn't need to be a plugin, this is required only if you want to use the script from the GUI.
You can do that in Imagemagick command line. For Imagemagick 6 on Unix:
convert image.jpg -write mpr:img +delete \
\( mpr:img -resize W1xH1 +write result1.jpg \) \
\( mpr:img -resize W2xH2 +write result2.jpg \) \
\( mpr:img -resize W3xH3 +write result3.jpg \) \
...
null:
If on Windows
convert image.jpg -write mpr:img +delete ^
( mpr:img -resize W1xH1 +write result1.jpg ) ^
( mpr:img -resize W2xH2 +write result2.jpg ) ^
( mpr:img -resize W3xH3 +write result3.jpg ) ^
...
null:
If on Imagemagick 7, change convert to magick
I got this working code for tiling an image in ImageMagick:
convert D:\tile.jpg -resize 300x300 -write mpr:tiler +delete ^
-size 900x900 tile:mpr:tiler -sharpen 0x2 D:\tiles.jpg
But now i found out that i need to add watermark in the same process. I got this working code for that:
tiles.jpg Wartermark.png -gravity southeast -geometry +0+0 -composite D:\tile-watermark.jpg
But how do i process those two in one line?
I'm currently using Photoshop to resize, rotate randomly, and wrap images randomly to create this type of montage....
Comic Covers
I got to thinking that kind of thing should be doable in Imagemagick. I know how to use all of the commands separately, and I can do random rotations and wraps using BASH, but getting a single image out of individual images is eluding me.
Assume that the source pictures are different sizes but should be resized to 250px wide. The images will be named image1.jpg, image2.jpg, etc. Also assume that the destination should be 1000x1000px. Depending on how many pictures I have, the whole 1000x1000 image may not be covered - I understand this. I mainly use BASH, but I have several different environments and shells available to me.
Using ImageMagick 6 or 7, if you have enough memory to read in all your images at once you can resize them, randomly rotate them, and place them all in random locations on a 1000x1000 canvas with a command like this...
convert granite: -duplicate 11 -resize 250x \
-background none -gravity center -extent 1000x1000 \
-distort SRT "%[fx:rand()*45-22.5]" -virtual-pixel tile \
-distort affine "%[fx:w/2],%[fx:h/2] %[fx:rand()*w],%[fx:rand()*h]" \
-flatten result.png
That uses the ImageMagick built-in image "granite:" duplicated 11 more times. Replace "granite: -duplicate 11" with a list of your input files.
It starts by resizing them all to 250 pixels wide, then placing them each in the center of a 1000x1000 transparent canvas.
The real work is done in the distort operations. First "-distort SRT" rotates each image a random amount between -22.5 and +22.5 degrees. Then the "-distort affine" relocates each image to a random location within the canvas. Any part of an image going beyond the canvas will be rolled back into the opposite side. That makes the result suitable for tiling.
This command flattens everything onto a transparent background wherever it might show between the images. Add "-background blue" just before the "-flatten" operation to change the background to blue, for example.
This works on my IM 6 in bash. For IM 6 in Windows change the continued line backslashes "\" to carets "^". For IM version 7 change "convert" to "magick".
Here is a bash Imagemagick 6 script that takes a list of images. You can replace it with your images. It uses subshell processing to avoid needing to write temporary images to disk. It saves the images in a miff: format as one file from the loop. Then it pipes the multipage miff: file to -layers merge, which overlays the images onto the 1000x1000 transparent base image. For Imagemagick 7, replace convert with magick.
list="lena.jpg barn.jpg mandril3.jpg zelda1.jpg"
convert -size 1000x1000 xc:none result.png
(
for img in $list; do
angle=`convert xc: -format "%[fx:round(-22.5+45*(rand()))]" info:`
xoff=`convert xc: -format "%[fx:round(1000*rand())]" info:`
yoff=`convert xc: -format "%[fx:round(1000*rand())]" info:`
#echo >&2 "angle=$angle; xoff=$xoff; yoff=$yoff"
convert "$img" -resize 250x -background none -rotate $angle -set page +${xoff}+${yoff} miff:-
done
) | convert result.png - -layers merge +repage result.png
If you have enough resources to hold all the images at once, then you can also do it in one command line as follows:
convert -size 1000x1000 xc:none \
\( lena.jpg barn.jpg mandril3.jpg zelda1.jpg -virtual-pixel none -background none \
+distort SRT "0,0 %[fx:250/w] %[fx:-22.5+45*rand()] %[fx:rand()*1000],%[fx:rand()*1000]" \) \
-layers merge +repage result.png
Cool, I'll try fmw42's script, but this is a script I came up with. It generates temporary files (which it deletes) and several convert commands, but it does work....
# Create blank montage...
convert -size 750x750 xc:black montage.jpg
for file in $(ls hall*.jpg | grep -v halloweencovers.jpg); do
echo $file
angle=$RANDOM; let "angle %= 32"; let "angle = angle - 16"; let "angle = angle * 5"
offsetx=$RANDOM; let "offsetx %= 75";let "offsetx = offsetx * 10"; offsetx="+$offsetx"
offsety=$RANDOM; let "offsety %= 75";let "offsety = offsety * 10"; offsety="+$offsety"
# Create blank image...
convert -size 750x750 xc:transparent blank.png
# create 250px image and rotate....
convert $file -resize 250x -alpha set -background none -rotate $angle out.png
# add 250px image to blank 750x750 canvas
convert blank.png out.png -composite output.png
# offset and wrap blank canvas with output image
convert output.png -roll ${offsetx}${offsety} output2.png
# merge montage with offset image
convert montage.jpg output2.png -composite montage.jpg
# clean up
rm -f out.png output.png output2.png blank.png
done
I recently started working with Imagemagick and I had a problem that needs to be solved.
I have such a thumbnail.
And there is such a mask.
I need to get this image on the output.
I looked through this link http://www.imagemagick.org/Usage/thumbnails/ I tried everything there, but I did not get success ((
I hope you will help me.
This should give you a result very much like your example...
convert mask.png image.png -gravity north -composite \
mask.png -compose copyopacity -composite result.png
You can adjust the positioning of the overlay by including something like "-geometry -10+0" before the first composite.
To use this command in Windows you'll need to change that continued line backslash "\" to a caret "^".
In Imagemagick, you should extract the alpha channel of your mask and put that into the alpha channel of your other image. So try
(unix syntax)
convert KlQZ6.png \( 7k9a9.png -alpha extract \) -alpha off -compose copy_opacity -composite result.png
(windows syntax)
convert KlQZ6.png ( 7k9a9.png -alpha extract ) -alpha off -compose copy_opacity -composite result.png
Original Image
convert image.jpg -scale 310x496\! scaled.png
convert scaled.png +clone -flip -crop 310x150 -compose Dst -composite out/shadow.png
convert -size 310x150 -alpha set gradient:rgba\(255,0,255,0.6\)-rgba\(255,255,0,0.50\) out/grad.png
convert out/shadow.png out/grad.png -compose Dst_Out -composite out/shadow_gradiented.png
convert shadow_gradiented.png out/shadowed.png -append out/final.png
I am getting following output
But I want my output to be like following.
What am i doing wrong? Suggest me.
Additional:
Is there any way I can make all in one command.
Not certain what you are trying to achieve, but this might get you started:
convert wolf.jpg -scale 310x496\! \
\( +clone -flip -crop x150+0+0\! -alpha set -channel A -fx "0.6" \) -append result.png
If you want the alpha tailing off, try a formula that is a function of j (the distance from the top of the reflection) and h (the total height of the reflection).
convert wolf.jpg -scale 310x496\! \
\( +clone -flip -crop x150+0+0\! -alpha set -channel A -fx "0.8-(0.6*j)/h" \) -append result.png
If you want the code to be a bit more generic, and less dependent on actual sizes, you could change the height of the reflection to, say 1/4, of the height of the original (note the change from convert to magick)
magick wolf.jpg -scale 310x496\! \
\( +clone -flip -crop "x%[fx:h/4]+0+0\!" -alpha set -channel A -fx "0.8-(0.6*j)/h" \) -append result.png