Descrizione

Copy a part of src_im onto
dst_im starting at the x,y coordinates
src_x, src_y with
a width of src_w and a height of
src_h. The portion defined will be copied
onto the x,y coordinates, dst_x and
dst_y.

Elenco dei parametri

dst_im

Risorsa link dell'immagine di destinazione

src_im

Risorsa link dell'immagine originale

dst_x

x-coordinate of destination point.

dst_y

y-coordinate of destination point.

src_x

x-coordinate of source point.

src_y

y-coordinate of source point.

src_w

Larghezza dell'originale.

src_h

Altezza dell'originale.

pct

The two images will be merged according to pct
which can range from 0 to 100. When pct = 0,
no action is taken, when 100 this function behaves identically
to imagecopy() for pallete images, except for
ignoring alpha components, while it implements alpha transparency
for true colour images.

Valori restituiti

Restituisce TRUE in caso di successo, FALSE in caso di fallimento.

Esempi

Example #1 Merging two copies of the PHP.net logo with 75% transparency

User Contributed Notes 25 notes

I've just checked PHP's issue tracker and a core developer says that this function was never meant to support alpha channel! and they refused to commit the provided patch! so ridicules
Anyway i tried rodrigo's workaround and it worked quite well, thanks rodrigo for sharing it.
I came up with another idea which is much faster than his solution, (it may need a little bit more memory)

Building upon backglancer's and stefan's posts below, the following script will lay a 24-bit PNG watermark over any image.

To prepare a 24-bit watermark, I recommend creating a white logo or text over a transparent background in Photoshop. Save this as a 24-bit PNG via 'Save for the Web...'. Be sure to set the transparency of the logo layer in Photoshop itself. 30-40% is a good setting.

Once the assets are prepared, throw the full or relative server paths at the watermark function below:

// remember we don't need gif any more, so we use only png or jpeg. // See the upsaple code immediately above to see how we handle gifs case('png'): header("Content-type: image/png"); imagepng ($sourcefile_id); break;

I was about to kill myself....any one of you trying to merge a SEMI transparent png...use imagecopy :)<?$flag = imagecreatefrompng('flags/images/flagWhiteFill.png');$mask = imagecreatefrompng('flags/images/flag_transparent.png');

The following function creates mask of a true color image for a given color. Beforehand for creating an image mask I used to loop over all image pixels and check their color using imagecolorat and copy if the color matches with imagesetpixel. This was very slow for large images, so the following code improves the process.

So for example, if we have a photo and we specify color = (255, 0, 0), i.e. red, the result will be image of the same size with red pixels everywhere the original photo was red and grey pixels exerywhere else.

I needed to draw a "pointer" image over a map, but had some problems with png image transparency.So I created a png image with white background (not transparent) and merged it on my map, after defining white color as transparent:

This function is intended to serve as an example for the "imageCopyMerge"-"ImageCopyResized", "ImageColorTransparent" functions. I hope it will help. This function pick an image, square cut it resampled at the size requested and finishing merge the result with another one to obtain a circular image result. I have a problem to obtain an thumbnail that respect the colors and at the same time where cutted in a circular form, I hope this solution can gives you a clue to obtain a free form images, I use this one also to create multicutted images.

i found that if you use imagecopymerge with png-24 files with an alpha channel, it doesn't work use imagecopy instead.it seems that imagecopymerge doesn't respect the alpha channel the way it should (a bug??).

some sample code here to place an image (image.png) on a backgroundcolor or backgroundimage.

// create a truecolor background image of the right size// or use a background image like this// $backgroundimage = imageCreateFromPNG($backgroundfile);$backgroundimage = imagecreatetruecolor($im_X, $im_Y);

// get the desired backgroundcolor:// don't use this if you want to use a background image$code = colordecode($bg);$backgroundcolor = ImageColorAllocate($backgroundimage, $code[r], $code[g], $code[b]);ImageFilledRectangle($backgroundimage, 0, 0, $im_X, $im_Y, $backgroundcolor);

Task: Rotate a large image, then reduce it in size and place it on a small background (i.e. as an Inset).

Problem: If you resize the image first, the rotation becomes hugely aliased... So, it makes sense to rotate it first, then shrink it.Unfortunately, when you resample the image, you lose the background color (at least, some of it may change), so you can no longer set transparancy as you require. If instead you resize the image (rather than resample), again, the aliasing looks bad.

Solution: Resize the background - make it bigger. Then add the original (large) inset, and resize the whole thing back to normal.

If you need to merge 2 png's (or presumably 2 gifs) with different color palettes, I have found this is the function to use. Just set pct to 99, and you are rocking. With pct set to 100, or imagecopy for that matter, the palette seems to go wonky. (It probably just uses the palette of the source image. but don't quote me on that).

This function is intended to serve as an example for the "imageCopyMerge"-function.
I hope it will help some of the less experienced php-coders here.
I wrote it to mark objects of a real estate broker as "sold" by copying the "sold"-picture right into the picture of the house.

<?php

//$sourcefile = Filename of the picture into that $insertfile will be inserted.
//$insertfile = Filename of the picture that is to be inserted into $sourcefile.
//$targetfile = Filename of the modified picture.
//$transition = Intensity of the transition (in percent)
//$pos = Position where $insertfile will be inserted in $sourcefile
// 0 = middle
// 1 = top left
// 2 = top right
// 3 = bottom right
// 4 = bottom left
// 5 = top middle
// 6 = middle right
// 7 = bottom middle
// 8 = middle left
//
//
function mergePix($sourcefile,$insertfile, $targetfile, $pos=0,$transition=50)
{

Hii wrote this script to add a watermark image into the bottom right a larger image. Its very basic i know but its all i need for now. It also is an easy function for noobs to grasp. It just takes an two image types as arguments

This is what I use for merging two images while respecting the alpha channel (formulas are taken from the wikipedia article on alpha compositing; they're not too pretty as I didn't really try to make them look so, but instead just work and make sense when checked out months from now), with a quirk - an additional parameter (that defaults to NULL to be ignored) to manually specify a "transparent" color, which won't be copied over from the source to the destination. In comparison to the other implementation here, only one pass over $src_im is done, but more calculations are performed:

Anyone wanting to create a reflecion of an image. Simple process that copies, line by line, from the bottom of the image, a given number of pixels. Each line gets gradually more transparent. Outputs PNG to screen.

This is pretty hot-coded - all four input variables (input image, reflection height, starting transparency, gap between image and reflection) are set manually here.

Try running this however and an omitted detail adds to the fun. Since the first colour that is defined is taken to be the background colour, we have a random colour selected from $origim as the background colour for $imagetodisplay, but this random colour is weighted according to the background image. It was a surprise (I thought the bg would be black) but I am now keeping it as it looks good.

I found on the internet about a thousand copies of this "imageCopyMerge" script of Stefan.

Most of them had a copyright notice of the copyist added, but none of them had added what a starting user of PHP scripting really needs: The lines to be used in a HTML page, where the result of the script will be visible:

I was so lucky to get these lines from someone on the internet, after I posted my question all over the world. Most other people that replied, referred to the bookstore. But I had first read halve the (this) PHP manual, and had not found it.

Just a suggestion, but I know it will help many people getting started with PHP: When you put your scripts here, why not add those few lines needed to incorporate it into a HTML page?