Merging Images Vertically in Multipe of 2 - imagemagick

I have a situation where from a folder , I would like to merge 1 and 2 nd image vertically , 3rd and 4th Image vertically and so forth .
I have searched and found that Image magic does merging of images but not in any order . Is it possible to do it in Command Line .
Scenario: Files inside the folder 1.png , 2.png , 3.png upto say 60.png
Expected Output : Merge 1.png and 2.png vertically stacked one below the other Merge 3.png and 4.png vertically stacked one below the other . SO that I would be having 30 images finally .
I am using Ubuntu.

You can do it like this:
#!/bin/bash
out=0
for ((i=1;i<60;i+=2)); do
((j=i+1))
((out=out+1))
A=${i}.png
B=${j}.png
echo Stacking $A and $B to make result-${out}.png
magick "$A" "$B" -smush 10 "result-${out}.png"
done

Related

Missing layer when Combining images into PSD using ImageMagick

I'm trying to combine 3 images using imageMagicks 7 latest version however the first layer is always missing.
convert "image_03.png" "image_02.png" "image_01.png" -background none -alpha set "product.psd"
However i only get two layers??
Attached are the images below ...
A PSD file expects a layer that is the flattened layer from all the other layers. It needs to be the first layer. Photoshop assumes the first layer is the flattened layer. It must be created in Imagemagick and combined with the other individual layers as the first image in the command sequence when writing a PSD file. So I create it last from clones and then insert it at the first position (0).
Try the following.
Unix syntax:
convert "image_03.png" "image_02.png" "image_01.png" \( -clone 0-2 -flatten \) -insert 0 -background none -alpha set "product.psd"
If on Windows, remove the \s from in front of the parentheses.
Reorder the images as desired for the layers in the PSD file.

How to copy an image line and insert it at specified positions n-times with imagemagick?

I have some pixel based images that I would like to manipulate with imagemagick in the following way.
Each image follows the same pixel-line format:
aaaaaaaaaaaaaaa
bbbbbbbbbbbbbbb
bbbbbbbbbbbbbbb
ccccccccccccccc
ccccccccccccccc
bbbbbbbbbbbbbbb
bbbbbbbbbbbbbbb
aaaaaaaaaaaaaaa
So what I would like to do is to copy the first bbbb line and insert it after last b line before the c lines and after the last b lines after the c lines. This will expand the images height.
This process should be repeated n-times.
This means that the a and c lines part will be left untouched, while the b parts will blow up the height of the image.
After reading imagemagick option summary I have no clue how this could be done.
So any kind of help would be appreciated.
Thanks to #fmw42 I could script the following solution which gets the image size and then calculates the number of lines to increase the image to a height of 48/49 pixel.
First it adds the lines at the image bottom and after this it adds the same number of lines at the image top. While keeping the first/last lines.
#echo off
setlocal ENABLEDELAYEDEXPANSION
set image=Welcome1.gif
rem use %1 for comanndline argument
set image2=%TEMP%\temp1.gif
set image3=%TEMP%\temp2.gif
magick identify -format "%%w" %image% > %TEMP%\imwidth.txt
set /P width=<%TEMP%\imwidth.txt
del %TEMP%\imwidth.txt
magick identify -format "%%h" %image% > %TEMP%\imheight.txt
set /P height=<%TEMP%\imheight.txt
del %TEMP%\imheight.txt
set /A addlines=(49 - %height%) / 2
set /A lastline=%height% - 2
magick %image% -crop %width%x1+0+2 %TEMP%\copyLine.gif
rem Add lines at end of image
set image1=%image%
FOR /L %%i IN (1,1,%addlines%) DO (
magick !image1! -background black -splice 0x1+0+%lastline% %image2%
magick composite %TEMP%\copyLine.gif %image2% -geometry 99x1+0+%lastline% %image3%
del %TEMP%\%image%
ren %image3% %image%
set image1=%TEMP%\%image%
)
rem Add lines at top of image
set image1=%TEMP%\%image%
FOR /L %%i IN (1,1,%addlines%) DO (
magick !image1! -background black -splice 0x1+0+2 %image2%
magick composite %TEMP%\copyLine.gif %image2% -geometry 99x1+0+2 %image3%
del %TEMP%\%image%
ren %image3% %image%
set image1=%TEMP%\%image%
)
copy %TEMP%\%image% %image:~0,-4%touch.gif
del %TEMP%\copyLine.gif %TEMP%\temp1.gif %TEMP%\temp2.gif %TEMP%\%image%
endlocal
exit /b 0

Black line between 2 images while using append on imagemagick

I have two files;
1.jpg = 14000x2800 pixels
2.jpg = 2800x128 pixels
I use the following command:
...\convert.exe -auto-orient -quality 100 -append "1.jpg" "2.jpg" "out.jpg"
The goal is to merge the images together on the vertical axis, and it works great but now I need to add a straight horizontal black line between images (line's length should be the biggest file's length, meaning from left to right) while appending.
Is there any way to do that without a second command?
Easier description with MSPaint skills
Here's a way to do it:
magick 1.jpg 2.jpg -size "%[fx:u.w>v.w?u.w:v.w]x10" xc:black -swap 2,1 -append result.png
That says... load 1.jpg and 2.jpg. Define the width for the canvas we create next as "whatever is the wider of 1.jpg (referred to as u) and 2.jpg (referred to as v)" by 10 pixels tall. Create a black canvas that size. Now swap the order so that the canvas we just created is between the two images. Append all 3 images and save.
That gives you one of these, depending which one you load first:
If you want the unfilled, white background area beside the narrower image to be, say magenta, use:
magick -background magenta 1.jpg 2.jpg -size "%[fx:u.w>v.w?u.w:v.w]x10" xc:black -swap 2,1 -append result.png
Keywords: ImageMagick, image processing, wider, widest, taller, tallest, match existing image width, match height.

Create character sheet using imagemagick

I currently modding for F1 Challenge 99 02 and i want to change the game font. The format F1C uses is basically a sheet of characters arranged in a grid-like formation. Below is an example:
How can i make similar images with a desired font using Imagemagick (or other cli software)?
I modified one of my Windows scripts and tested it with ImageMagick 6.8.9-9 on a bash shell.
The first part of it uses a couple "for" loops and "sed" to create a text file containing a list of all the characters.
> chars.txt
for x in 2 3 4 5 6 7 8 9 A B C D E F ;
do for y in 0 1 2 3 4 5 6 7 8 9 A B C D E F ;
do echo X | sed "s/.*/label:\x${x}${y}/g" >> chars.txt ;
done ;
done
The lines in that file look like this...
label:
label:!
label:"
label:#
label:$
label:%
...
The prefix "label:" on each line lets IM read that file as if it's a long list of individual labels. IM reads that file like this "#chars.txt" to get all the images to create the character sheet. Here is the IM command that works on my bash...
imfont=Times-Roman
convert -font ${imfont} -pointsize 24 -size 36x36 -gravity center -background none \
label:"\ " #chars.txt +gravity -compose copy -bordercolor blue -shave 1 -border 1 \
+append +repage -crop 360x36 -append +repage charsheet.png
You should be able to make the grid from any installed font by setting the variable "imfont" to your choice.
The grid is created on a transparent background. To put it on a colored background, white for example, use "-background #FFFFFF -flatten" before writing the output file.
Edited to add: Notice how the command includes the "label:\ " for the space character ahead of reading the list of labels. On my installation IM won't make a label for a space unless I escape it with a backslash "\", so I just add that label manually.

ImageMagick: montaging image from different-sized tiles

I'm developing a script to download images from tile-based image-hosting.
I downloaded tiles using wget and trying to use montage to compine them.
The problem is that I've got tiles with different sizes (last tile in row is more narrow than the others). Here is combine command:
montage $temp/*.jpg -tile $maxcolumn"x"$maxrow -geometry -1-1 -quality 100% merged.jpg
ImageMagick aligns tiles by grid and produces this image (see right and bottom sides).
image http://leftparagraphs.ru/!/merged.jpg
How do I fix this with montage?
Fixed by specifying "-mode Concatenate".
Also I have to run another instance of convert after montage to "-trim" resulting image.
This solution did not work for me. To combine two different height images into one, I first used the identify command to get the height of the largest image (1280 pixels):
identify large.jpg
Then I used the following command to resize the smaller image and combine it side by side with the larger one:
montage -tile 2x1 -geometry +0+0 small.jpg"[x1280]" large.jpg output.jpg

Resources