imagecopy

(PHP 4, PHP 5)

imagecopyCopy part of an image

Description

bool imagecopy ( resource $dst_im , resource $src_im , int $dst_x , int $dst_y , int $src_x , int $src_y , int $src_w , int $src_h )

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.

Parameters

dst_im

Destination image link resource.

src_im

Source image link resource.

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

Source width.

src_h

Source height.

Return Values

Returns TRUE on success or FALSE on failure.

Examples

Example #1 Cropping the PHP.net logo

<?php
// Create image instances
$src imagecreatefromgif('php.gif');
$dest imagecreatetruecolor(8040);

// Copy
imagecopy($dest$src0020138040);

// Output and free from memory
header('Content-Type: image/gif');
imagegif($dest);

imagedestroy($dest);
imagedestroy($src);
?>

The above example will output something similar to:

Output of example : Cropping the PHP.net logo

Коментарии

simple image combination srcipt, ie. if u want to create one  huuuge signature from more small ones

<?php
// config --
$src = array ("http://www.google.com/images/logo_sm.gif""http://sk2.php.net/images/php.gif");   
$under 0;    // combine images underneath or not?
// -- end of config

$imgBuf = array ();
$maxW=0$maxH=0;
foreach (
$src as $link)
{
    switch(
substr ($link,strrpos ($link,".")+1))
    {
        case 
'png':
           
$iTmp imagecreatefrompng($link);
            break;
        case 
'gif':
           
$iTmp imagecreatefromgif($link);
            break;               
        case 
'jpeg':           
        case 
'jpg':
           
$iTmp imagecreatefromjpeg($link);
            break;               
    }

    if (
$under)
    {
       
$maxW=(imagesx($iTmp)>$maxW)?imagesx($iTmp):$maxW;
       
$maxH+=imagesy($iTmp);
    }
    else
    {
       
$maxW+=imagesx($iTmp);
       
$maxH=(imagesy($iTmp)>$maxH)?imagesy($iTmp):$maxH;
    }

   
array_push ($imgBuf,$iTmp);
}

$iOut imagecreate ($maxW,$maxH) ;

$pos=0;
foreach (
$imgBuf as $img)
{
    if (
$under)
       
imagecopy ($iOut,$img,0,$pos,0,0,imagesx($img),imagesy($img));
    else
       
imagecopy ($iOut,$img,$pos,0,0,0,imagesx($img),imagesy($img));   
   
$pos+= $under imagesy($img) : imagesx($img);
   
imagedestroy ($img);
}

imagegif($iOut);
?>
2005-10-21 11:48:51
http://php5.kiev.ua/manual/ru/function.imagecopy.html
Here a function to make holes into images:

// Set the alpha channel for a part of an image (it ignores the canvas alpha atm).
// $img_canvas - 32-bit true color image w/ alpha channel
// $img_mask - 8-bit gray scale image (white parts will be masked transparent in the canvas).
// This relies on the current pixel format:
// (high byte) -> (alpha channel} {red} {green} {blue} <- (low byte)
function mask($img_canvas, $img_mask, $dst_x, $dst_y)
{
   $old_blendmode = imagealphablending($img_canvas, FALSE);

   $width  = imagesx($img_mask);
   $heigth = imagesy($img_mask);

   $mask_x = 0;
   $x = $dst_y;
   while ($mask_x<$width)
   {
       $mask_y = 0;
       $y = $dst_y;
       while ($mask_y<$heigth)
       {
           imagesetpixel($img_canvas, $x, $y,
               ((imagecolorat($img_mask, $mask_x, $mask_y) >> 1) << 24) | (imagecolorat($img_canvas, $x, $y) & 0x00FFFFFF));

           ++$mask_y;
           ++$y;
       }
       ++$mask_x;
       ++$x;
   }

   imagealphablending($img_canvas, $old_blendmode);
}
2005-11-21 05:17:13
http://php5.kiev.ua/manual/ru/function.imagecopy.html
Skewing images in PHP...
<?php
function Skew($src$dest$skew_val)
{
 
$imgsrc imagecreatefromgif($src);
 
$width imagesx($imgsrc);
 
$height imagesy($imgsrc);
 
$imgdest imagecreatetruecolor($width$height+($height*$skew_val));
 
$trans imagecolorallocate($imgdest,0,0,0);
 
$temp=0;
  for(
$x=$x<$width $x++)
   {
     for(
$y=$y<$height $y++) 
    {
       
imagecopy($imgdest$imgsrc$x$y+$temp$x$y11);
     
imagecolortransparent($imgdest,$trans);
       
    }
   
$temp+=$skew_val;
   }
 
imagepng($imgdest$dest); 
 
imagedestroy($imgsrc);
 
imagedestroy($imgdest);
}
Skew("img.gif""img2.png","1");
print 
"<img src='img.gif'>";
print 
"<br><br>";
print 
"<img src='img2.png'>";
?>
2006-02-09 13:38:04
http://php5.kiev.ua/manual/ru/function.imagecopy.html
I used this to watermark images. This is the function I wrote:

<?php
function watermark($url,$logo){
   
$bwidth  imagesx($url);
   
$bheight imagesy($url);
   
$lwidth  imagesx($logo);
   
$lheight imagesy($logo);
   
$src_x $bwidth - ($lwidth 5);
   
$src_y $bheight - ($lheight 5);
   
ImageAlphaBlending($urltrue);
   
ImageCopy($url,$logo,$src_x,$src_y,0,0,$lwidth,$lheight);
}
?>

Usage:
<?php
//$current_image would be your image the watermark is overlayed onto. Make sure it's imagecreatefrom*** to work.
watermark($current_image,$watermark_image);
?>

Hope this helps someone.
2006-02-23 10:26:00
http://php5.kiev.ua/manual/ru/function.imagecopy.html
Автор:
While replying to a post in a support forum I noticed something odd about imagecopy(). The first snippet (should) create an image object, allocate a colour resource within that image, fill the background with the allocated colour and then copy another, cropped to fit, image onto it.

<?php
   
// create a new image resource
   
$temp imagecreatetruecolor$width$height );
   
$white imagecolorallocate$temp255255255 );

   
//fill the background with white
   
imagefill$temp00$white );

   
//copy the image into new a resource
   
imagecopy($temp$this->Image00$crop_top$crop_left$width$height);
?>

But this produces a black background. I noticed taking away the imagefill() call yields the same results. The solution was to call imagefill() after the imagecopy(). Thinking linearly I would have guessed this to cover the previously copied image in white but it doesn't. I guess GD uses a layer system? Is this correct?

<?php
   
// create a new image resource
   
$temp imagecreatetruecolor$width$height );
   
$white imagecolorallocate$temp255255255 );

   
// copy image into new resource
   
imagecopy$temp$this->Image00$crop_top$crop_left$width$height );
       
   
//fill the background with white (not sure why it has to be in this order)
   
imagefill$temp00$white );
?>

I am using php 5.1.4 with the bundled GD (2.0.28)
2006-08-16 14:02:55
http://php5.kiev.ua/manual/ru/function.imagecopy.html
Here is an upgrade of that cool wave function: Double the size of the image, wave it, then resample it down again. This makes even nicer, anti aliased waves.

    // So easy and nice!
    function wave_region($img, $x, $y, $width, $height,$amplitude = 4.5,$period = 30)
    {
        // Make a copy of the image twice the size
        $mult = 2;
        $img2 = imagecreatetruecolor($width * $mult, $height * $mult);
        imagecopyresampled ($img2,$img,0,0,$x,$y,$width * $mult,$height * $mult,$width, $height);

        // Wave it
        for ($i = 0;$i < ($width * $mult);$i += 2)
        {
           imagecopy($img2,$img2,
               $x + $i - 2,$y + sin($i / $period) * $amplitude,    // dest
               $x + $i,$y,            // src
               2,($height * $mult));
        }
       
        // Resample it down again
        imagecopyresampled ($img,$img2,$x,$y,0,0,$width, $height,$width * $mult,$height * $mult);
        imagedestroy($img2);
    }

To use it in a full image:
    wave_region ($oImage,0,0,imagesx($oImage),imagesy($oImage));
2007-01-17 07:37:22
http://php5.kiev.ua/manual/ru/function.imagecopy.html
Автор:
I came across the problem of having a page where any image could be uploaded, then I would need to work with it as a true color image with transparency. The problem came with palette images with transparency (e.g. GIF images), the transparent parts changed to black (no matter what color was actually representing transparent) when I used imagecopy to convert the image to true color.

To convert an image to true color with the transparency as well, the following code works (assuming $img is your image resource):

<?php
//Convert $img to truecolor
$w imagesx($img);
$h imagesy($img);
if (!
imageistruecolor($img)) {
 
$original_transparency imagecolortransparent($img);
 
//we have a transparent color
 
if ($original_transparency >= 0) {
   
//get the actual transparent color
   
$rgb imagecolorsforindex($img$original_transparency);
   
$original_transparency = ($rgb['red'] << 16) | ($rgb['green'] << 8) | $rgb['blue'];
   
//change the transparent color to black, since transparent goes to black anyways (no way to remove transparency in GIF)
   
imagecolortransparent($imgimagecolorallocate($img000));
  }
 
//create truecolor image and transfer
 
$truecolor imagecreatetruecolor($w$h);
 
imagealphablending($imgfalse);
 
imagesavealpha($imgtrue);
 
imagecopy($truecolor$img0000$w$h);
 
imagedestroy($img);
 
$img $truecolor;
 
//remake transparency (if there was transparency)
 
if ($original_transparency >= 0) {
   
imagealphablending($imgfalse);
   
imagesavealpha($imgtrue);
    for (
$x 0$x $w$x++)
      for (
$y 0$y $h$y++)
        if (
imagecolorat($img$x$y) == $original_transparency)
         
imagesetpixel($img$x$y127 << 24);
  }
}
?>

And now $img is a true color image resource
2007-02-22 17:27:34
http://php5.kiev.ua/manual/ru/function.imagecopy.html
Автор:
I had the same problem as Jeff, but his solution didn't work for me. I made this script, and it seems to work:

<?php

$img 
imagecreatefromgif('in.gif');
$w imagesx($img);
$h imagesy($img);

$trans imagecolortransparent($img);
if(
$trans >= 0) {

$rgb imagecolorsforindex($img$trans);

$oldimg $img;
$img imagecreatetruecolor($w,$h);
$color imagecolorallocate($img,$rgb['red'],$rgb['green'],$rgb['blue']);
imagefilledrectangle($img,0,0,$w,$h,$color);
imagecopy($img,$oldimg,0,0,0,0,$w,$h);

}

imagegif($img,'out.gif');

?>
2008-02-02 07:22:00
http://php5.kiev.ua/manual/ru/function.imagecopy.html
Автор:
Here is some simple code for resizing an uploaded image and inserting a watermark (from a 24-bit PNG) on the bottom right of it.  In this case, the water mark was a diagnol band that said "SOLD" across it.  The code that verifies the uploaded image is the correct type has been omitted:

<?PHP
//Load and resize the image
$uploaded imagecreatefromjpeg($_FILES['file']['tmp_name']);
$image imagecreatetruecolor(IMAGE_WIDTHIMAGE_HEIGHT);
imagecopyresampled($image$uploaded0000IMAGE_WIDTHIMAGE_HEIGHTimagesx($uploaded), imagesy($uploaded));   
imagealphablending($image,true); //allows us to apply a 24-bit watermark over $image

//Load the sold watermark
$sold_band imagecreatefrompng('../images/sold_band.png');
imagealphablending($sold_band,true);

//Apply watermark and save
$image image_overlap($image$sold_band);
imagecopy($image,$sold_band,IMAGE_WIDTH SOLD_WIDTH,IMAGE_HEIGHT SOLD_HEIGHT,0,0,SOLD_WIDTH,SOLD_HEIGHT);
$success imagejpeg($image,'../images/sold/'.$id.'.jpg',85);

imagedestroy($image);
imagedestroy($uploaded);
imagedestroy($sold_band);
?>
2008-07-08 14:40:13
http://php5.kiev.ua/manual/ru/function.imagecopy.html
Автор:
concerning the previous post of Borszczuk and the function to mirror images:

There´s a way better (and faster) method for this task with imagecopyresampled.

<?php

define 
'IMAGE_FLIP_HORIZONTAL');
define 'IMAGE_FLIP_VERTICAL');
define 'IMAGE_FLIP_BOTH');

function 
ImageFlip $imgsrc$mode )
{

   
$width                        =    imagesx $imgsrc );
   
$height                       =    imagesy $imgsrc );

   
$src_x                        =    0;
   
$src_y                        =    0;
   
$src_width                    =    $width;
   
$src_height                   =    $height;

    switch ( (int) 
$mode )
    {

        case 
IMAGE_FLIP_HORIZONTAL:
           
$src_y                =    $height;
           
$src_height           =    -$height;
        break;

        case 
IMAGE_FLIP_VERTICAL:
           
$src_x                =    $width;
           
$src_width            =    -$width;
        break;

        case 
IMAGE_FLIP_BOTH:
           
$src_x                =    $width;
           
$src_y                =    $height;
           
$src_width            =    -$width;
           
$src_height           =    -$height;
        break;

        default:
            return 
$imgsrc;

    }

   
$imgdest                    =    imagecreatetruecolor $width$height );

    if ( 
imagecopyresampled $imgdest$imgsrc00$src_x$src_y$width$height$src_width$src_height ) )
    {
        return 
$imgdest;
    }

    return 
$imgsrc;

}

?>
2008-09-27 08:53:57
http://php5.kiev.ua/manual/ru/function.imagecopy.html
I have a few remarks om the mirror-function:
The cases horizontal and vertical are switched.
1 = vertical and 2 = horizontal.
When I used it there appeared a black lining of 1 pixel on the side or on the top of the picture.
To remove it the function becomes as follows:

<?php
function ImageFlip $imgsrc$mode )
{

   
$width                        =    imagesx $imgsrc );
   
$height                       =    imagesy $imgsrc );

   
$src_x                        =    0;
   
$src_y                        =    0;
   
$src_width                    =    $width;
   
$src_height                   =    $height;

    switch ( 
$mode )
    {

        case 
'1'//vertical
           
$src_y                =    $height -1;
           
$src_height           =    -$height;
        break;

        case 
'2'//horizontal
           
$src_x                =    $width -1;
           
$src_width            =    -$width;
        break;

        case 
'3'//both
           
$src_x                =    $width -1;
           
$src_y                =    $height -1;
           
$src_width            =    -$width;
           
$src_height           =    -$height;
        break;

        default:
            return 
$imgsrc;

    }

   
$imgdest                    =    imagecreatetruecolor $width$height );

    if ( 
imagecopyresampled $imgdest$imgsrc00$src_x$src_y $width$height$src_width$src_height ) )
    {
        return 
$imgdest;
    }

    return 
$imgsrc;

}
?>
2009-03-18 06:38:22
http://php5.kiev.ua/manual/ru/function.imagecopy.html
Автор:
Simple and basic image cropping:

<?php
// Original image
$filename 'someimage.jpg';

// Get dimensions of the original image
list($current_width$current_height) = getimagesize($filename);

// The x and y coordinates on the original image where we
// will begin cropping the image
$left 50;
$top 50;

// This will be the final size of the image (e.g. how many pixels
// left and down we will be going)
$crop_width 200;
$crop_height 200;

// Resample the image
$canvas imagecreatetruecolor($crop_width$crop_height);
$current_image imagecreatefromjpeg($filename);
imagecopy($canvas$current_image00$left$top$current_width$current_height);
imagejpeg($canvas$filename100);
?>
2009-05-27 10:55:26
http://php5.kiev.ua/manual/ru/function.imagecopy.html
This is based on the Skew function from designerkamal at gmail dot com.

This is a function for skewing images in PHP with anti-aliasing. It works with alpha PNG images.

Warning: the bigger the image you skew, the longer it will take to process. It's about 3 times longer than without anti-aliasing.

<?php
// $img: handle of an image
// $skew_val: level of skew to apply (0 being none, 1 being 45°)
function imageskewantialiased($img$skew_val)
{
   
$width imagesx($img);
   
$height imagesy($img);
   
$height2 $height + ($width $skew_val);
   
   
// See below for definition of imagecreatealpha
   
$imgdest imagecreatealpha($width$height2);
   
   
// Process the image
   
for($x 0$level 0$x $width 1$x++)
    {
       
$floor floor($level);
       
       
// To go faster, some lines are being copied at once
       
if ($level == $floor)
           
imagecopy($imgdest$img$x$level$x01$height 1);
        else
        {
           
$temp $level $floor;
           
           
// The first pixel of the line
            // We get the color then apply a fade on it depending on the level
           
$color1 imagecolorsforindex($imgimagecolorat($img$x0));
           
$alpha $color1['alpha'] + ($temp 127);
            if (
$alpha 127)
            {
               
$color imagecolorallocatealpha($imgdest$color1['red'], $color1['green'], $color1['blue'], $alpha);
               
imagesetpixel($imgdest$x$floor$color);
            }
           
           
// The rest of the line
           
for($y 1$y $height 1$y++)
            {
               
// Merge this pixel and the upper one
               
$color2 imagecolorsforindex($imgimagecolorat($img$x$y));
               
$alpha = ($color1['alpha'] * $temp) + ($color2['alpha'] * ($temp));
                if (
$alpha 127)
                {
                   
$red   = ($color1['red']   * $temp) + ($color2['red']   * ($temp));
                   
$green = ($color1['green'] * $temp) + ($color2['green'] * ($temp));
                   
$blue  = ($color1['blue']  * $temp) + ($color2['blue']  * ($temp));
                   
$color imagecolorallocatealpha($imgdest$red$green$blue$alpha);
                   
imagesetpixel($imgdest$x$floor $y$color);
                }
               
               
$color1 $color2;
            }
           
           
// The last pixel of the line
           
$color1 imagecolorsforindex($imgimagecolorat($img$x$height 1));
           
$alpha $color1['alpha'] + (($temp) * 127);
            if (
$alpha 127)
            {
               
$color imagecolorallocatealpha($imgdest$color1['red'], $color1['green'], $color1['blue'], $alpha);
               
imagesetpixel($imgdest$x$floor $height 1$color);
            }
        }
       
       
// The line is finished, the next line will be lower
       
$level += $skew_val;
    }
   
   
// Finished processing, return the skewed image
   
return $imgdest;
}

// Creates a new image of the size specified with a blank background (transparent)
function imagecreatealpha($width$height)
{
   
// Create a normal image and apply required settings
   
$img imagecreatetruecolor($width$height);
   
imagealphablending($imgfalse);
   
imagesavealpha($imgtrue);
   
   
// Apply the transparent background
   
$trans imagecolorallocatealpha($img000127);
    for (
$x 0$x $width$x++)
    {
        for (
$y 0$y $height$y++)
        {
           
imagesetpixel($img$x$y$trans);
        }
    }
   
    return 
$img;
}

// Here's an example of how to use it
imagepng(imageskewantialiased(imagecreatefrompng('test.png'), 0.15), 'skew.png');
?>
2009-07-03 05:16:45
http://php5.kiev.ua/manual/ru/function.imagecopy.html
Автор:
Regarding the image_flip function discussed in the notes here, don't forget to support transparency.

AFTER: 

$imgdest = imagecreatetruecolor($width, $height); 

ADD:

imagealphablending($imgdest, false);
imagesavealpha($imgdest, true);

In another post here it mentioned you didn't have to use the imagesavealpha function, but I found without it the background transparency can turn the background canvas black.
2009-07-06 15:20:19
http://php5.kiev.ua/manual/ru/function.imagecopy.html
I have created a PHP function which performs the standard 9-Slice scaling technique. This is extremely useful for thumbnail shadow scaling, and anything involving skinning. Feel free to pick apart and use

Note: instead of specifying margins, my 9-slicing routine uses a centered-rectangle concept... as input you provide the image (as a resource), the x and y coords of the rectangle, and the width and height of the rectangle.

The $src_im parameter should be an image resource. This script was written for 9-slicing translucent PNG images, and has only been tested with translucent PNG images, however it should work with other image types (possibly requiring some modification)

so if your source image was 400 x 400, you needed a 24 pixel margin on all sides, and your target size was 800 x 500, you would use the following parameters:

<?php
$im 
NineSlice($im2424352352800500)
?>

<?php
/* 9-Slice Image Slicing Script by Sam Kelly (DuroSoft: http://www.durosoft.com) */
function NineSlice($src_im$rect_x$rect_y$rect_w$rect_h$target_w$target_h)
{
   
$src_w imagesx($src_im);
   
$src_h imagesy($src_im);
   
   
$im CreateBlankPNG($target_w$target_h);
   
imagealphablending($im,true);
   
   
$left_w $rect_x;
   
$right_w $src_w - ($rect_x $rect_w);
   
   
$left_src_y ceil($rect_h 2) - $rect_y;
   
$right_src_y $left_src_y;
   
   
$left_src_x 0;
   
$right_src_x $left_w $rect_w;
   
   
$top_src_x ceil($rect_w 2) - $rect_x;
   
$bottom_src_x $top_src_x;
   
$bottom_src_y $rect_y $rect_h;
   
$bottom_h $src_h $bottom_src_y;
   
   
$left_tile CreateBlankPNG($left_w1);
   
imagecopy($left_tile$src_im000$left_src_y$left_w1);
   
   
$right_tile CreateBlankPNG($right_w1);
   
imagecopy($right_tile$src_im00$right_src_x$right_src_y$right_w1);

   
$top_tile CreateBlankPNG(1$rect_y);
   
imagecopy($top_tile$src_im00$top_src_x01$rect_y);
   
   
$bottom_tile CreateBlankPNG(1$bottom_h);
   
imagecopy($bottom_tile$src_im00$bottom_src_x$bottom_src_y1$bottom_h);
   
   
$inner_tile CreateBlankPNG(44);
   
imagecopy($inner_tile$src_im00ceil($src_w 2) - 1ceil($src_h 2) - 144);
   
   
imagecopy($im$src_im0000$left_w$rect_y);
   
imagecopy($im$src_im0$target_h $bottom_h0$bottom_src_y$rect_x$bottom_h);
   
imagecopy($im$src_im$target_w $right_w0$right_src_x0$right_w$rect_y);
   
imagecopy($im$src_im$target_w $right_w$target_h $bottom_h$src_w $right_w$bottom_src_y$right_w$bottom_h);

   
imagesettile($im$top_tile);
   
imagefilledrectangle($im$left_w0$target_w $right_w 1$rect_yIMG_COLOR_TILED);
   
   
imagesettile($im$left_tile);
   
imagefilledrectangle($im0$rect_y$left_w$target_h $bottom_h 1IMG_COLOR_TILED);
   
   
   
$right_side CreateBlankPNG($right_w$target_h $rect_y $bottom_h);
   
imagesettile($right_side$right_tile);
   
imagefilledrectangle($right_side00$right_w$target_h $rect_y $bottom_hIMG_COLOR_TILED);
   
imagecopy($im$right_side$target_w $right_w$rect_y00$right_w$target_h $rect_y $bottom_h);
   
   
$bottom_side CreateBlankPNG($target_w $right_w $left_w$bottom_h);
   
imagesettile($bottom_side$bottom_tile);
   
imagefilledrectangle($bottom_side00$target_w $right_w $left_w$bottom_hIMG_COLOR_TILED);
   
imagecopy($im$bottom_side$right_w$target_h $bottom_h00$target_w $right_w $left_w$bottom_h);

   
imagedestroy($left_tile);
   
imagedestroy($right_tile);
   
imagedestroy($top_tile);
   
imagedestroy($bottom_tile);
   
imagedestroy($inner_tile);
   
imagedestroy($right_side);
   
imagedestroy($bottom_side);
   
    return 
$im;
}

function 
CreateBlankPNG($w$h)
{
   
$im imagecreatetruecolor($w$h);
   
imagesavealpha($imtrue);
   
$transparent imagecolorallocatealpha($im000127);
   
imagefill($im00$transparent);
    return 
$im;
}
 
?>
2009-09-22 22:29:55
http://php5.kiev.ua/manual/ru/function.imagecopy.html
There is function to crop blank edges from image.

<?php
/**
* $image image cursor (from imagecreatetruecolor)
* $backgound image curosr (from imagecolorallocate)
* $paddng int 
*/
function imageCrop($image$background false$padding 0) {
    if(
$background)
     
$background imagecolorallocate($image255255255);
   
   
$top imageSY($image);
   
$left imageSX($image);
   
$bottom 0;
   
$right 0;
   
    for (
$x $x imagesx($image) ; $x++) {
        for (
$y $y imagesy($image) ; $y++) {
         
         
// if there match
           
if(imagecolorat($image$x$y) != $background) {
             
              if(
$x $left)
               
$left $x;
              if(
$x $right)
               
$right $x;
              if(
$y $bottom)
               
$bottom $y;
              if(
$y $top)
               
$top $y;
        }
        }
    }
   
   
$right++;
   
$bottom++;
   
   
// create new image with padding
   
$img imagecreatetruecolor($right-$left+$padding*2,$bottom-$top+$padding*2);
   
// fill the background
   
imagefill($img00$background);
   
// copy 
   
imagecopy($img$image$padding$padding$left$top$right-$left$bottom-$top);
   
   
// destroy old image cursor
   
imagedestroy($image);
    return 
$img;
}
?>
2010-05-11 10:23:00
http://php5.kiev.ua/manual/ru/function.imagecopy.html

    Поддержать сайт на родительском проекте КГБ