Imagick::compositeImage

(No version information available, might be only in CVS)

Imagick::compositeImage — Composite one image onto another

Описание

bool Imagick::compositeImage ( Imagick $composite_object , int $composite , int $x , int $y [, int $channel ] )
Внимание

К настоящему времени эта функция еще не была документирована; для ознакомления доступен только список аргументов.

Composite one image onto another at the specified offset.

Список параметров

composite_object

Imagick object which holds the composite image

compose

Composite operator. See Composite Operator Constants

x

The column offset of the composited image

y

The row offset of the composited image

channel

Provide any channel constant that is valid for your channel mode. To apply to more than one channel, combine channeltype constants using bitwise operators. Defaults to Imagick::CHANNEL_ALL. Refer to this list of channel constants.

Возвращаемые значения

Returns TRUE on success.

Коментарии

Here is a way to composite an image onto another : 

//Creating two Imagick object
$first = new Imagick('first.jpg');
$second = new Imagick('second.jpg');

//Second image is put on top of the first
$first->compositeImage($second, $second->getImageCompose(), 5, 5);

//new image is saved as final.jpg
$first->writeImage('final.jpg');
2007-07-31 16:44:42
http://php5.kiev.ua/manual/ru/function.imagick-compositeimage.html
Here is an example on how to compose two images into a single one. The Imagick class utilises the exception handling model introduced in PHP5 and thus we will do that as well. Let's presume, that we have a directory in our filesystem, which contains our program and the two images we want to operate on.

<?php
try
{
   
// Let's check whether we can perform the magick.
   
if (TRUE !== extension_loaded('imagick'))
    {
        throw new 
Exception('Imagick extension is not loaded.');
    }

   
// This check is an alternative to the previous one.
    // Use the one that suits you better.
   
if (TRUE !== class_exists('Imagick'))
    {
        throw new 
Exception('Imagick class does not exist.');
    }

   
// Let's find out where we are.
   
$dir dirname(__FILE__);

   
// Let's read the images.
   
$glasses = new Imagick();
    if (
FALSE === $glasses->readImage($dir '/glasses.png'))
    {
        throw new 
Exception();
    }

   
$face = new Imagick();
    if (
FALSE === $face->readImage($dir '/face.jpg'))
    {
        throw new 
Exception();
    }

   
// Let's put the glasses on (10 pixels from left, 20 pixels from top of face).
   
$face->compositeImage($glassesImagick::COMPOSITE_DEFAULT1020);

   
// Let's merge all layers (it is not mandatory).
   
$face->flattenImages();

   
// We do not want to overwrite face.jpg.
   
$face->setImageFileName($dir '/face_and_glasses.jpg');

   
// Let's write the image.
   
if  (FALSE == $face->writeImage())
    {
        throw new 
Exception();
    }
}

catch (
Exception $e)
{
    echo 
'Caught exception: ' $e->getMessage() . "\n";
}

exit(
0);
?>
Also a couple more words on the Imagick::COMPOSITE_DEFAULT argument. The images we are composing together are separate layers. Not only can we put them in specific order, but we can also choose the way we want them to interfere with each other. And here comes the second argument of the compositeImage method. It can be given either as a constant or as the integer value of that constant. You can use the reflection API of PHP5 to get the list of them.

<?php
Reflection
::export(new ReflectionClass('Imagick'));
?>

Just look for COMPOSITE_* constants in the "Constants" section.
2008-02-13 04:55:42
http://php5.kiev.ua/manual/ru/function.imagick-compositeimage.html
You might need to set the colorspace the same when composing two images over each other

<?php
//Creating two Imagick object
$first = new Imagick('first.jpg');
$second = new Imagick('second.jpg');

// Set the colorspace to the same value
$first->setImageColorspace($second->getImageColorspace() );

//Second image is put on top of the first
$first->compositeImage($second$second->getImageCompose(), 55);

//new image is saved as final.jpg
$first->writeImage('final.jpg');
?>
2010-01-20 18:30:57
http://php5.kiev.ua/manual/ru/function.imagick-compositeimage.html
Автор:
To copy the alpha channel from one image to another, you can do the following:

<?php

$img1 
= new Imagick"image1.png" );
$img2 = new Imagick"image2.png" );

$img1->compositeImage$img2imagick::COMPOSITE_COPYOPACITY0);

header('Content-type: image/png');
echo 
$img1;

?>
2011-07-06 08:01:40
http://php5.kiev.ua/manual/ru/function.imagick-compositeimage.html

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