Composite operation with im4java - imageMagick - imagemagick

I want to use imagemagick/im4java to combine two images into a single image -
I have a command that works great in command line.
'composite -gravity center -geometry +25+0 image1.png -compose multiply
image2.png output.png`
I want to achieve the same results using im4java.core package, I have this set of commands but it does not give me the right result.
CompositeCmd composite = new CompositeCmd()
IMOperation operation = new IMOperation();
operation.gravity("center")
operation.geometry(25,0)
operation.addImage()
operation.compose("multiply")
operation.addImage()
operation.addImage()
composite.run(operation, "image1.png","image2.png", "output3.png")

Related

Compose multiple regions of an image into a target

I'm trying to use ImageMagick to compose different pieces of a rendered PDF into a target. E.g., I want to have ImageMagick render the PDF at 300dpi, then create a 300x400 pixel output image, then take from the PDF the area 10x20+30+40 and place it in the target (300x400 pixel image) at 12,34. Then take another (and a third and fourth) chunk at different coordinates with different sizes and place them at different places.
I cannot seem to figure out how to do this in one go, and doing it in multiple runs always re-renders the PDF and takes awfully long. Is this even possible?
Here's an idea of how you can approach this. It uses the MPR or "Memory Program Register" that Fred suggested in the comments. It is basically a named chunk of memory that I write into at the start and which I recall later when I need it.
Here is a rather wonderful start image from the Prokudin-Gorskii collection:
The code resizes the image and saves a copy in the MPR. Then, takes a copy of the MPR, crops out a head, resizes it and composites the resized result onto the resized original at a different location and then repeats the process for another head.
magick Prokudin.png -resize 300x400\! -write MPR:orig \
\( MPR:orig -crop 50x50+180+84 -resize 140x140 \) -geometry +10+240 -compose src-over -composite \
\( MPR:orig -crop 40x40+154+184 \) -geometry +40+100 -compose src-over -composite \
result.png
If you have trouble understanding it, try running it with the second or third line omitted so it just does one head ;-)
Hopefully it covers all the aspects of your question and you can adapt it to your PDF.

Imagemagick - pngs onto png

i've a huge png image (4000x3000, big.png), and i've smaller images (1500x200, small_n.png) .
I'd like to put the small images onto the big.png based on a starting (x,y) parameter.
So, for instance I've the small_1.png with the starting point (300, 200), and this point should represent the top left corner of the image. How can I put the small_1.png onto the big.png knowing the starting point?
I'd like to use imagemagick, or if not possible, any linux commandline tool.
Thanks.
In ImageMagick, you can do that as follows:
convert large_image.png small_image.png -geometry +300+200 -compose over -composite result.png
If you have several small images, you can repeat the same process multiple times in the same command line.
convert large_image.png small_image1.png -geometry +X1+Y1 -compose over -composite small_image2.png -geometry +X2+Y2 -compose over -composite result.png
If using ImageMagick 7, replace convert with magick.
See https://imagemagick.org/Usage/layers/#convert

Crop and merge two images using ImageMagick

I am trying to use ImageMagick to place one image (Poseidon_map01.jpg in my code below) in the top-left corner of another (zzOcean Backdrop.png) then crop the resulting image down to 1280x720.
This is the command I currently have:
".\ImageMagick-7.0.8-12-portable-Q16-x64\magick.exe" ".\Raw\zzOcean Backdrop.png" ".\Raw\Poseidon_map01.jpg" -gravity northwest -composite -crop 1280x720>! +repage ".\1280x720\Poseidon_map01.jpg"
The problem is that this command is cutting the composited image into 1280x720 pieces then saving all of those pieces with the names Poseidon_map01-1.jpg to Poseidon_map01-48.jpg. Poseidon_map01-1.jpg is the top-left corner of the composited image and this is the piece that I want to keep. I want to discard the rest of the composite. Does anyone know what I have to change in my command to make this happen? Thanks.
In Imagemagick crop, if you do not include the +X+Y offsets, it will crop as many pieces as it can given the size you specify. That is called tiled cropping. So use -crop WxH+X+Y>!
See https://imagemagick.org/Usage/crop/#crop
".\ImageMagick-7.0.8-12-portable-Q16-x64\magick.exe" ".\Raw\zzOcean Backdrop.png" ".\Raw\Poseidon_map01.jpg" -gravity northwest -composite -crop 1280x720+0+0>! +repage ".\1280x720\Poseidon_map01.jpg"
I am not a windows user and syntax may vary some. You may need to escape the > or ! with ^ on windows or put double quotes around the whole crop set of arguments. Keep that in mind, if this does not work. See https://imagemagick.org/Usage/windows/

Two-step watermark applying using imagemagick

I am trying to apply watermark to an image of any size using two steps in one command line:
Tile small png image and overlay it over the target image.
Overlay a logo at top left corner without tiling.
I don't understand the imagemagick command line principles and can't create a command line to make these operations without creatig temporary file between steps 1 and 2. But I am sure this is possible :)
Please help me to do that.
Thanks.
There are many ways to achieve this, but the simplest would be to leverage ImageMagick's Stack notation "()".
Simply group the first step into a command wrapped in parentheses, and omit the output filename.
convert \( \
wizard: \
-size 480x640 \
-background transparent \
tile:label.png -composite \
\) \
-gravity NorthEast rose: \
-composite output.png
The above will compose the label.png as a repeating image over the wizard: image. Note, in this example I provided the -size and -background attributes. The result of the Image Stack will be accepted as the input image for the second -composite operation; which, places the rose: image in the top right.

Add an image on top of existing one with ImageMagick command line

i would like to add a series of images to existing one, using imagemagick command line.
i have this image: http://tinypic.com/r/313386r/6 and
i would like to add this to this one: http://tinypic.com/r/k0jbqs/6
to get more or less this effect: http://tinypic.com/r/wtja74/6 .
as you see, this is not only adding an image. i found http://www.imagemagick.org/Usage/compose/ where i could see some examples, but what i need is to fill each 'block'.
i have exact position where each block starts and ends, also i have a scale parameter to scale it down.
i think i could use
composite -geometry +31+105 toadd.gif source.gif newfile.jpg
but this is only one image added, and i need it scaled down.
i was wondering if i can create some kind of rectangles and fill them with my image.
any idea how it can be solved?
Convert would be better as you can keep adding images with composite or layers.
Here is a very rough example and I would probably start off with a longer section of wall so you could crop it when resizing. There is still going to be quite a bit of user input to fix the locations as I pressume you do not always have the same amount of walls at the same length.
I would write some code to input details into a form as it would be easier than altering the code each time.
convert k0jbqs.jpg \
( 313386r.png -thumbnail x25 ) -gravity west -geometry +0+30 -composite \
( 313386r.png -thumbnail x25 ) -gravity center -geometry +80+30 -composite \
( 313386r.png -thumbnail x25 ) -gravity east -geometry +0+30 -composite \
output.png
You would need to take the line breaks out I just added those to make the code readable.
NOTES: Thumbnail resizes the brick image; you can forget the gravity and just use -geometry and the numbers are the positions from the top left corner and -composite puts the new image over the previous image.

Resources