Home > front end >  imagemagic: combine two grid images
imagemagic: combine two grid images

Time:02-01

I have two big images with identical dimensions. Each image composed on the 4x6 elements splited in the form of grid (table) with identical border. Here is the both inputs in resized format (actual resolution is 7384x2872) enter image description here

enter image description here

Is it possible to use any utilities of Image Magic or other software working on Mac, to take any number of the central grids (surrounded by a perimeter by other elements) from the first image and insert it to the same central position of the image 2 (thus making a substitution of selected grids )?

CodePudding user response:

Let's call your first image a.jpg and the second b.jpg and assume we want to copy the right-most cell from the second row of the first into the second.

Now that cell is 112x64 and at offset 577 69 from the top-left corner, so we want to:

  • load the first image
  • crop out the cell
  • load the second image
  • put the second image at the bottom
  • flatten the cropped part of the first image onto the second

That looks like this:

magick a.jpg -crop 112x64 577 69 b.jpg  swap -flatten result.jpg

I have made an animation of the a.jpg, b.jpg and the result here:

enter image description here


If you dislike doing things in the "wrong" order, you can do exactly the same thing by loading b.jpg first, then in some bracketed "aside-processing" loading and cropping just a.jpg before flattening:

magick b.jpg \( a.jpg -crop 112x64 577 69 \) -flatten result.jpg
  • Related