简体   繁体   English

PHP-Imagick:模式图像不透明

[英]PHP-Imagick : Pattern image is loosing opacity

I am trying to tile/loop a simple pattern-image over a canvas-image . 我正在尝试在canvas-image 图像上平铺/循环一个简单的图案 canvas-image Here is a relevant code-snippet. 这是一个相关的代码片段。

$image = new \Imagick();
$image->newPseudoImage(700, 400, "canvas:black");
$image->setImageFormat("png");
$texture = new \Imagick(realpath('pattern.png'));
$image = $image->textureImage($texture);
header("Content-Type: image/png");
echo $image;

The pattern-image ( pattern.png ) is titling across the canvas just fine, but somehow it seems like transparency of pattern.png is messed up in the process. pattern-image (pattern.png)在画布上的标题很好,但是在某种程度上好像pattern.png的透明度被弄乱了。 Here is the result I am getting. 这是我得到的结果。

结果不好


Here is what the result image is expected to look like. 这就是结果图像的外观。

预期结果


Just in case, here is a var_dump of $texture->getImageProperties(); 以防万一,这里是$texture->getImageProperties();var_dump $texture->getImageProperties();

array (size=8)
  'date:create' => string '2015-10-18T09:59:01+05:00' (length=25)
  'date:modify' => string '2015-02-08T20:53:20+05:00' (length=25)
  'png:IHDR.bit-depth-orig' => string '8' (length=1)
  'png:IHDR.bit_depth' => string '8' (length=1)
  'png:IHDR.color-type-orig' => string '0' (length=1)
  'png:IHDR.color_type' => string '0 (Grayscale)' (length=13)
  'png:IHDR.interlace_method' => string '0 (Not interlaced)' (length=18)
  'png:IHDR.width,height' => string '68, 34' (length=6)

ENVIRONMENT : 环境

PHP Version 5.5.12
Wampserver2.5
Apache-2.4.9-
Imagick 3.1.2
mageMagick 6.8.9-1 Q16 x64 2014-05-08
Windows 7 : 64 Bit.

FOOTNOTES : Although I have no clue where to start looking, I have started to check out the alpha channels. 脚注 :尽管我不知道从哪里开始寻找东西,但我已经开始检查Alpha通道。 Also, other images are working fine so this could also be image-specific problem. 另外,其他图像工作正常,因此这也可能是特定于图像的问题。 Perhaps, that the image being an 8-bit ?? 也许,该图像是8位的? Do I need to remove transparency from the pattern.png ? 我是否需要从pattern.png中删除透明度? If so how do I do it? 如果是这样,我该怎么办? Gimme your 2 cents :) 给你2美分:)


TRIED SO FAR THAT DID NOT WORK: 尝试失败了这么远:

  • $image->setImageFormat("png24");
  • $texture->setImageAlphaChannel(Imagick::ALPHACHANNEL_DEACTIVATE);

Well, according to feedback in comments section, it seems to be an issue with the version of imagick/imagmagick I have. 好吧,根据评论部分的反馈,这似乎与我拥有的imagick / imagmagick版本有关。 Since I was not allowed to upgrade, here is an alternative I came up with, in case someone may find it useful. 由于不允许我进行升级,因此我想出了一个替代方案,以防有人发现它有用。

$pattern = new Imagick(realpath('pattern.png')); // Create a new pattern object 
$pw = $pattern->getImageWidth();
$ph = $pattern->getImageHeight();

    $draw = new ImagickDraw(); // Create imagickdraw object 
    $draw->pushPattern('pattern', 0, 0, $pw, $ph);  // Create a pattern identifier 
    $draw->composite(Imagick::COMPOSITE_OVER, 0, 0, $pw, $ph, $pattern); // Composite the pattern 
    $draw->popPattern(); // Close the pattern 
    $cw = 700;
    $ch = 400;

    $draw->push();
    $draw->setFillPatternURL('#pattern');   
    //$draw->setFillColor('yellow');
    $draw->rectangle(0, 0, $cw, $ch);
    $draw->pop();

$canvas = new Imagick(); // Create a new canvas object
$canvas->newImage($cw, $ch, "none");
$canvas->drawImage($draw); // Draw the ImagickDraw on to the canvas 
$canvas->setImageFormat('png'); // Set the format to PNG 
header("Content-Type: image/png"); // Output the image 
echo $canvas; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM