Search code examples
phpimagick

php Imagick color overlay


Okay i think i maybe have misundertode the function of colorizeImage in the Imagick. Im trying to add 70% black color to a image. But the code only works if its 1 and then its just a black image.

but from the manual i can't seem to find the problem. http://php.net/manual/en/imagick.colorizeimage.php

$backdropInFile = JPATH_BASE . '/images/movies/'.$_POST["movieid"].'/backdrop'.$movie['backdrop_path'];
$backdropOutFile = JPATH_BASE . '/images/movies/'.$_POST["movieid"].'/backdrop/'.$_POST["movieid"].'_backdrop.jpg';
$backdropimage = new Imagick($backdropInFile);
$backdropimage->setImageCompression(Imagick::COMPRESSION_JPEG);
$backdropimage->setImageCompressionQuality(60);
$backdropimage->colorizeImage('#000',0.9);
$backdropimage->thumbnailImage(1700, null);
$backdropimage->writeImage($backdropOutFile);

does some one know what is wrong, or have another way to do this?


Solution

  • Okay i found a solution to the problem, by doing it a another way. Here the code

    $backdropInFile = JPATH_BASE . '/images/movies/'.$_POST["movieid"].'/backdrop'.$movie['backdrop_path'];
    $backdropOutFile = JPATH_BASE . '/images/movies/'.$_POST["movieid"].'/backdrop/'.$_POST["movieid"].'_backdrop.jpg';
    $backdropimage = new Imagick();
    $backdropimage->setBackgroundColor('black');
    $backdropimage->readimage($backdropInFile);
    $backdropimage->setImageOpacity(0.25);
    $backdropimage->setImageCompression(Imagick::COMPRESSION_JPEG);
    $backdropimage->setImageCompressionQuality(60);
    $backdropimage->thumbnailImage(1700, null);
    $backdropimage = $backdropimage->flattenImages();
    $backdropimage->writeImage($backdropOutFile);
    

    I stead of using colorize, i set the background color to be black before openning the file. Then i set the image to be 25% transparent. And then i flatten the image and save.