How I Can Composite image with imagemagick with this file? - imagemagick

When i want to composite one image with png file i use:
exec("convert 1.png ".$newfile1." -geometry +110+70 -compose DstOver -composite ".$result_image);
And when i want use Perspective i use :
exec('convert '.$newfile1.' -matte -background transparent -virtual-pixel background -distort Perspective "0,0 0,0 393,0 236,65 393,486 393,486 0,486 153,486" '.$newfile1.'');
But with this png file for example :
create Perspective file is very different and hard because i don't know the source image size and how create best perspective..
any help?
(soryy for my bad english)

Related

How to fuse 2 image and keep the same filename / overwrite the original

I have 3 png image: a red square with a transparent background (1.png), a map (PLAN.png) and a color gradient with a transparent background (LEGEND.png). I want to first put the red square atop the map and then put the color gradient atop of it, while keeping the original filename of the red square for multiple files in multiple folders
Here's what I came up with in the windows cmd:
cd [location of the folder]
magick convert ../PLAN.png 1.png -compose multiply -composite 1.png && magick composite ../LEGEND.png 1.png 1.png
The problem is that for each file, I need to manually change 1.png to for example 1 2 3.png . I had used this command:
magick mogrify -gravity center -draw "image Over 0,0 0,0 '../PLAN2.png'" *.png
While with it I don't have to manually manually change the 1.png, it doesn't work with the map since it put it atop of the red square
In ImageMagick 7, do the following. Note, use magick, not magick convert.
magick PLAN.png 1.png -compose over -composite LEGEND.png -compose over -composite 1.png
or
magick PLAN.png 1.png LEGEND.png -background none -flatten 1.png
Do either of those do what you want?

imagemagick compose one transparent png(as mask) with one jpg

I have 2 type of images.
Some hundreds of png images with just one color(gray) and some transparent zones then must be transparent even in final result.
Over 30 thousands of jpg images with many size.
I must estrapolate from jpg images the gray zones of png files.
Now i use something like this :
convert JPG_FILE.jpg -resize WIDTH_OF_PNGxHEIGHT_OF_PNG^ -gravity Center -crop WIDTH_OF_PNGxHEIGHT_OF_PNG+0+0 -alpha Set PNG_FILE.png ( -clone 0,1 -alpha Opaque -compose Hardlight -composite ) -delete 0 -compose In -composite RESULT_IMAGE.png
it works very good but its a bit slow
any suggestion for faster execution?

ImageMagick: Replace All Image Tiles with Single Tile

I'm assuming ImageMagick is the best option for this, but please let me know if you have other recommendations that can be scripted.
I am trying to replace all the 32x32 tiles of an image with a single tile. This is an example for the original image:
This is the tile that I want to use to replace all tiles on the original image:
And this is what I want the output to be:
I've figured out from other posts on Stack Overflow that I can use ImageMagick's composite option to overlay the tile onto the original image:
$ convert original.png tile.png -composite overlay.png
Resulting in the following:
And I assume by knowing the original images dimensions I can overlay the tile manually multiple times. But is there a way to automate the process. In the example pictures I have given, I need to overlay the tile 8 times on the original 64x128 image.
How can I do this with ImageMagick or another software? And if ImageMagick, would the montage or composite command be a better option?
Edit: As an additional question, would it be possible to skip tiles that are completely transparent?
Input example:
Output example:
It isn't really important to be able to do this part, but would be nice.
If the tile image fits evenly into the dimensions of the original, a command like this should do most of what you want...
convert original.png tile.png -background none -virtual-pixel tile \
-set option:distort:viewport %[fx:u.w]x%[fx:u.h] -distort SRT 0 +swap \
-compose copyopacity -composite overlay.png
That reads in both images. Then it creates another canvas the size of the original and filled with multiple copies of the tile image. Then it uses the original as a transparency mask to create a copy of the new tiled image with the same transparent cells as the original.
I don't know why you would need to overlay the 8 tiles on the original. Just create it from scratch and name the output the same as your original
You could use Imagemagick montage to do that (unix syntax):
nx=`convert original.png -format "%[fx:w/32]" info:`
ny=`convert original.png -format "%[fx:h/32]" info:`
num=$((nx*ny-1))
montage tile.png -duplicate $num -tile ${nx}x${ny} -geometry +0+0 result.png
Here I use convert to duplicated the tile, but it uses a relatively current -duplicate feature. If you do not have a current enough version of Imagemagick, then just repeat the tile in montage as follows:
montage Ro1Lp.png Ro1Lp.png Ro1Lp.png Ro1Lp.png Ro1Lp.png Ro1Lp.png Ro1Lp.png Ro1Lp.png -tile 2x8 -geometry +0+0 result.png
As Fred (fmw42) says, "why don't you just create the whole image from scratch?".
Maybe your description isn't complete, so here are a couple more pieces that might help you work it out.
Given bluetiles.png and singlered.png:
you can position red ones as you wish like this:
convert bluetiles.png \
singlered.png -geometry +0+32 -composite \
singlered.png -geometry +32+96 -composite result.png
Given bluewithtransparent.png:
you can copy its transparency to the newly-created image like this:
convert bluetiles.png \
singlered.png -geometry +0+32 -composite \
singlered.png -geometry +32+96 -composite \
\( bluewithtransparent.png -alpha extract \) -compose copyopacity -composite result.png

Export Multiple PSD Layer file to PNG while applying tint effect to each layer

We have the following PSD
https://app.box.com/s/rf514j3wnic1xkt6y1q3b5qnk0zds2rl
This is a transparent PSD with one base layer for the ring metal.
And additional layer for each individual stones.
Something like https://app.box.com/s/i8lhshbl27pvjmmczjq2bhla4mzw9cwn
and this
We want to be able to apply tint to each individual stone layer based of user input and export the final image as PNG file. To provide users the ability to design the ring to their liking.
Now I am trying to figure out what is the best way to achieve this functionality ?
We would like the image generated server side in .net so it can be shared.
What is the best way to approach this. I am thinking of using an image library like imagemagick to convert the image.
But I am unable to locate any examples where you can alter multiple layer with in a PSD file before converting it to another file format.
Any example or suggestion on methods to achieve this will of great help.
Editing layered PSD files is not going to be easy. I would suggest you maybe save the ring and each of the gemstone layers as a separate PNG file. Then you can do something along these lines with ImageMagick:
#!/bin/bash
convert ring.png \
\( layer-1.png \( +clone +level-colors red \) -compose Multiply -composite \) -compose overlay -composite \
\( layer-2.png \( +clone +level-colors green \) -compose VividLight -composite \) -compose overlay -composite \
\( layer-3.png \( +clone +level-colors blue \) -compose LinearBurn -composite \) -compose overlay -composite \
\( layer-4.png \( +clone +level-colors "#ffff00" \) -compose Saturate -composite \) -compose overlay -composite \
result.png
Giving you a PNG file like this:
You may like to experiment with the blending modes, I just tried a few that looked vaguely pleasing to my eye. If you want a list of all available blending modes, you can do:
identify -list compose
Atop
Blend
Blur
Bumpmap
ChangeMask
Clear
ColorBurn
ColorDodge
Colorize
CopyBlack
CopyBlue
CopyCyan
CopyGreen
Copy
CopyMagenta
CopyOpacity
CopyRed
CopyYellow
Darken
DarkenIntensity
DivideDst
DivideSrc
Dst
Difference
Displace
Dissolve
Distort
DstAtop
DstIn
DstOut
DstOver
Exclusion
HardLight
HardMix
Hue
In
Lighten
LightenIntensity
LinearBurn
LinearDodge
LinearLight
Luminize
Mathematics
MinusDst
MinusSrc
Modulate
ModulusAdd
ModulusSubtract
Multiply
None
Out
Overlay
Over
PegtopLight
PinLight
Plus
Replace
Saturate
Screen
SoftLight
Src
SrcAtop
SrcIn
SrcOut
SrcOver
VividLight
Xor
I also specified some colours by name and one by hex, so you can see how to do it that way if you prefer.
P.S. If you keep all your artwork as PSD files, you can always use Adobe's ExtendScript to script the export of the various layers as separate PNG files with a single keypress...
P.P.S. It is possible for ImageMagick to extract the layers from a PSD file itself, but I extracted the layers from your file and they are not all the same size as the background image and I cannot find their correct positioning relative to it. If you know something about how the layers were created and whether they could be made identical size and aligned with the background, you could replace layer-n.png in my examples with PhotoshopFile.psd[n]
P.P.P.S. If you want to do this server side in .NET you should take a look at the .NET library for ImageMagick that can be found here: https://magick.codeplex.com/. If you need help translating the commands above to C# you could ask a question on the discussions page there.

Masking an image's alpha in Imagemagick

I need to create an image to be used as a rollover background image. It's a circular pattern that is split into 8 pieces. Here's a screengrab of the main image (png with transparency):
And here's a screengrab of the mask image. It's the same size as the main image and features 'pie' pieces in order to mask all but the sector that is being hovered over.
I'm including screengrabs, as I believe the answer should be pretty simple (aren't all answers simple when you know them?!) so I'll save bandwidth, but I can upload the original files if it's helpful.
Here's the command I'm using to create the new masked image:
convert main.png \( mask.png -colorspace gray -alpha off \) \
-compose copy-opacity -composite new.png
The trouble is that the new image created has flattened the original image's alpha to a black background:
How do I get Imagemagick to preserve the original png's transparency?
You want masked composition to do this. http://imagemagick.org/Usage/compose/#mask
The technique is to compose the original image (the src) onto a fully transparent image of the same size (the dst), using a mask to limit composition area (the mask). It is a special case of the -composite operator, and involves 3 images, rather than 2 like the rest of the compose methods. You don't specify any -compose mode for this.
A quick way to get the fully transparent dst that you need for this technique is to clone the src image and zero out its alpha channel, then swap the order of src and dst so that they are in the right order for the -composite operation to follow:
convert main.png -alpha on \( +clone -channel a -fx 0 \) +swap mask.png -composite out.png
I was not satisfied with retroj's solution as it seems to ignore the grayscale of the mask.
This one worked for me:
composite -compose Dst_In \( mask.png -alpha copy \) main.png -alpha Set PNG32:result.png
or
convert -compose Dst_In \( mask.png -alpha copy \) main.png -alpha Set -composite PNG32:result.png
Dst_In method multiplies the alpha channels of two images. The trick here is to convert the grayscale mask to an alpha channel for it which is done with -alpha copy.

Resources