Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用Imagick转换透明PDF文件_Php_Imagick - Fatal编程技术网

Php 使用Imagick转换透明PDF文件

Php 使用Imagick转换透明PDF文件,php,imagick,Php,Imagick,我在用PHP和imagick创建缩略图时遇到问题。代码运行正常,缩略图大小正确,但当我尝试在缩略图上放置PDF徽标时,它会变成半透明。我猜这与InDesign中生成的PDF文件有关,而且可能没有定义任何背景。有没有人遇到过这个问题,或者知道该怎么办?我试着在背景中放一块白色的帆布,但没用。我还为compositeImage函数指定了一个通道,但这也没有帮助 这是我遇到问题的PDF文件: 生成的缩略图如下所示: 到目前为止,我编写的代码是:http://pastebin.com/74CYC972

我在用PHP和imagick创建缩略图时遇到问题。代码运行正常,缩略图大小正确,但当我尝试在缩略图上放置PDF徽标时,它会变成半透明。我猜这与InDesign中生成的PDF文件有关,而且可能没有定义任何背景。有没有人遇到过这个问题,或者知道该怎么办?我试着在背景中放一块白色的帆布,但没用。我还为compositeImage函数指定了一个通道,但这也没有帮助

这是我遇到问题的PDF文件: 生成的缩略图如下所示:

到目前为止,我编写的代码是:http://pastebin.com/74CYC972


有什么想法吗?谢谢你的帮助。

也许这就是你想要的:

$im->setBackgroundColor(new ImagickPixel('transparent')); 

这可能就是您想要的:

$im->setBackgroundColor(new ImagickPixel('transparent')); 

我也遇到了同样的问题,我通过以下方法解决了这个问题:

代码是这样的:

$im = new Imagick();
$im->readimage($pdfFile."[$currentPage]");
$res = $im->getimageresolution();

$bg = new Imagick();
$bg->setresolution($res["x"],$res["y"]); //setting the same image resolution

//create a white background image with the same width and height
$bg->newimage($im->getimagewidth(), $im->getimageheight(), 'white');
$bg->compositeimage($im, Imagick::COMPOSITE_OVER, 0, 0); //merging both images
$bg->setimageformat("png");

//then you can write to a file
$bg->writeImage('white-background-pdf-image.png');

//or output it
header('Content-type: image/png');
echo $bg;

我也遇到了同样的问题,我通过在这里找到的解决方法解决了这个问题:

代码是这样的:

$im = new Imagick();
$im->readimage($pdfFile."[$currentPage]");
$res = $im->getimageresolution();

$bg = new Imagick();
$bg->setresolution($res["x"],$res["y"]); //setting the same image resolution

//create a white background image with the same width and height
$bg->newimage($im->getimagewidth(), $im->getimageheight(), 'white');
$bg->compositeimage($im, Imagick::COMPOSITE_OVER, 0, 0); //merging both images
$bg->setimageformat("png");

//then you can write to a file
$bg->writeImage('white-background-pdf-image.png');

//or output it
header('Content-type: image/png');
echo $bg;

谢谢你的回答。不幸的是,这并没有改变任何事情。谢谢你的回答。不幸的是,这并没有改变任何事情。我的PDF缩略图功能也有同样的问题!这很痛苦,将背景设置为透明并不能解决这一问题。如果我渲染图像而不调整大小,尽管透明度问题消失了。我的PDF缩略图功能也有同样的问题!这很痛苦,将背景设置为透明并不能解决这一问题。如果我渲染图像而不调整大小,尽管透明度问题消失了。