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.
Related
I have around 2500 images. Some of them contains border while others arent. What I want to accomplish is to add border to the ones that doesn't have any.
Images with border are 64x64 and images without border are 56x56
I prepared a border image file with size of 64x64 in PNG format and I want to merge all files without border within this image to get them borders and output them as PNG format aswell.
I have tried several ways using ImageMagic but no luck so far.
If you make a 64x64 lime-magenta gradient as background.png and a solid blue 56x56 image as foreground.png like this:
magick -size 64x64 gradient:lime-magenta background.png
magick -size 56x56 xc:blue foreground.png
Your command to paste the foreground into the centre of the background is as simple as:
magick -gravity center background.png foreground.png -composite result.png
I figured out it's pretty doable with convert tool from the ImageMagick package.
First I extracted all images with size of 56x56 to different location, then I did the following;
I added 4 pixels on each side since my border is 64x64
for image in ICO_*.png; do
convert -page +0+0 border.png \
-page +4+4 $image \
-background none -layers merge +repage $image-withBorder.png
done
I am trying to crop and swap different parts of a big 800x800 image and re-create 800x800 image using imagemagick with this command.
magick mogrify titli.gif -crop 2x4# +repage -reverse -append -path converted titli.gif
my problem is "-append" creates tall image (400x1600) & "+append" creates wide image (3200x200)
How can I get a large image of original size 800x800 but with cropped and swapped (reversed) parts set in "mosaic or tiled" style...
If I understand the question, you shouldn't need "mogrify" to do that. Just "magick" should accomplish that task.
It looks like you'll have to crop the image into 8 pieces, reverse them, and "-append" them vertically as you've done.
Then after that, and in the same command, you'll need to crop that result in half vertically and "+append" those two pieces horizontally to get the 800x800 output.
This example command shows how it works...
magick in.png -crop 2x4# -reverse -append -crop 1x2# +append out.png
If you're doing any more operations within the same command you'll probably want to use "+repage" after the "+append" to reset the image geometry back to WxH+0+0.
I want to add logo on product image with engraving effect.
The original logo is
After adding it on the product it should look like this.
how to do this with imagemagick.
Using this as the trophy:
Then something along these lines:
convert trophy.jpg -gravity center \
\( G.png -colorspace gray -channel a -evaluate multiply 0.2 -resize 120x120 \) -composite result.png
So, I am basically loading the trophy, then in some "aside processing" in parentheses, loading the Google logo, converting it to greyscale, reducing the opacity by multiplying it by 0.2, resizing it and compositing it on top of the trophy.
By the way, if you were using GraphicsMagick, which doesn't have the parentheses I used to make sure I only convert the logo to greyscale and not the trophy, you would do it in a different order. First load the logo and process it (greyscale, resize etc), then load the trophy, then swap the order so the trophy goes to the background, like this:
gm convert G.png -colorspace gray -resize ... trophy.jpg -swap -composite result.png
I'm trying to execute the following set of transformations without knowing the absolute width or height of the target image:
1. Crop image A by 10px on every size :: A1
2. Create duplicate of A1 translating image by 1270px on the y-axis :: A2
3. Create montage of A1 && A2 :: A3
4. Translate A3 by 385px on the y-axis :: A4
5. Crop A4 at 100% width, and 1270px tall (box from 0,0 to WIDTH,1270) :: A5
My issue is how do I do steps 1 and 5 with relative coordinates? Below are my steps that I've come up with:
1. convert A.jpg -shave 10x10 A1.jpg
2. convert A1.jpg -page +0-1270 -background none -flatten A2.jpg
3. montage A1.jpg A2.jpg -geometry +0+0 A3.jpg
4. convert A3.jpg -page +0-385 -background none -flatten A4.jpg
5. convert A4.jpg ????? A5.jpg
Updated Answer
Ok, I think I understand what you want a bit better now. Here's how I would do it:
convert start.jpg -crop +0+383 +repage \
\( -clone 0 -crop x1270+0+0 \) \
\( -clone 0 -crop x1270+0+1270 \) \
-delete 0 +append result.jpg
The first line says..."Take the starting image and crop off the top 383 pixels and reset all the sizes to match what is left. Call that the first image from now onwards."
The second line says..."To one side (because of the parentheses), clone the first image and crop out the full width and 1270 pixels in height from the top. Hold onto that till later - i.e. keep it in the image list.".
The third line says..."To one side (because of the parentheses), clone the first image, and crop out a piece the full width and 1270 pixels in height, but start 1270 pixels from the top. Hold onto that till later - i.e. keep it in the image list."
The last line says..."Delete the initial image, and then take the two slices in the image list and append them side-by-side, Save as result.jpg".
Original Answer
I think we will need to work together on this one, but it can be done. Let's start with a concrete image that is a 400x250 gradient with a 15px black border:
convert -size 250x400 gradient:red-cyan -rotate 90 -bordercolor black -border 15 A.png
So, step 1.
convert A.png -shave 10x10 A1.png
Step 2&3. I don't get the point of these! You appear to be trying to add transparent space to a JPEG which doesn't support transparency. Also, I can't tell what you are montaging where. Please try and express what you want with these two steps in plain English, like "add a transparent area N pixels wide/tall above/below, left/right of A2", or maybe "add a transparent area such that the new dimensions are X,Y and the original A2 image is at the bottom-right of the new canvas."
If I have a stab at steps 2&3, I'll guess this (and add a purple border so you can see it on StackOverflow's white background). I am appending a transparent area 1270 pixels tall below the image.
convert A.png -background none -shave 10x10 xc:none[1x1270\!] -append b.png
Step 4&5. As above.
Or maybe you mean this:
convert A.png -background magenta -shave 10x10 -gravity southeast -extent 1270x385 result.png
I think we can get you down to a single command, with no intermediate files, if we understand your needs.
I have five images of sizes: 600x30, 600x30, 600x30, 600x30, 810x30. Their names are: 0.png, 1.png, 2.png, 3.png, 4.png, respectively.
How do I merge them Horizontally to make an image of size 3210x30 with ImageMagick?
ImageMagick ships with the montage utility. Montage will append each image side-by-side allowing you to adjust spacing between each image (-geometry), and the general layout (-tile).
montage [0-4].png -tile 5x1 -geometry +0+0 out.png
Other examples can be found on Montage Usage page
ImageMagick has command line tool named 'convert' to merge images horizontally, or for other purpose. i have tried this command and working perfectly on your case:
To join images horizontally:
convert +append *.png out.png
To stack images vertically:
convert -append *.png out.png
Use -resize if the images don't have the same width/height
You can fix the height for all of them with the -resize option, e.g. to fix a 500 pixel height on two images joined horizontally:
convert +append image_1.png image_2.png -resize x500 new_image_conbined.png
Or for vertical joins, you would want to set a fixed width instead:
convert -append image_1.png image_2.png -resize 500x new_image_conbined.png
Example:
image_1.png 1067x600
image_2.png 1920x1080
new_image_conbined.png 889x500
Related:
https://askubuntu.com/questions/226054/how-do-i-join-two-images-together
https://superuser.com/questions/290656/combine-multiple-images-using-imagemagick
How to do it interactively with GIMP
If you need to crop/resize images interactively first, which is often the case, then GIMP is the perfect tool for it, here's a detailed step-by-step: https://graphicdesign.stackexchange.com/questions/83446/gimp-how-to-combine-two-images-side-by-side/145543#145543
SVGs
ImageMagick 6.9.11-60 doesn't handle them, so see:
How to concatenate SVG files lengthwise from linux command line?
https://graphicdesign.stackexchange.com/questions/137096/is-there-a-way-to-stack-two-svgs-on-top-of-each-other
https://graphicdesign.stackexchange.com/questions/90844/joining-together-multiple-svg-images
Very simple with ImageMagick (brew install imagemagick )
convert +append image_1.png image_2.png new_image_conbined.png
Anyone using the MiniMagick rails gem can use the built-in tool to merge images:
# Replace this with the path to the images you want to combine
images = [
"image1.jpg",
"image2.jpg"
]
processed_image = MiniMagick::Tool::Montage.new do |image|
image.geometry "x700+0+0"
image.tile "#{images.size}x1"
images.each {|i| image << i}
image << "output.jpg"
end
Check out the documentation for #geometry options to handle resizing and placement. The current example will resize images to a 700px height while maintaining the image's aspect ratio. +0+0 will place the image with no gaps between them.
The convert +append method described in other answers appends images horizontally, aligned to the top. If you prefer to align to the bottom or center, try:
convert input1.png input2.png -gravity South +append output.png
or
convert input1.png input2.png -gravity Center +append output.png
Source: Fred's ImageMagick Tidbits http://www.fmwconcepts.com/imagemagick/tidbits/image.php#append