【问题标题】:imagecreatefrompng() with generated png from a php fileimagecreatefrompng() 从 php 文件生成 png
【发布时间】:2013-05-26 01:42:12
【问题描述】:

这段代码出错了

header ("Content-type: image/jpeg"); 

$nomphoto = "antigua.jpg";

// On charge d'abord les images
$source = imagecreatefrompng('logo.php');


$destination = imagecreatefromjpeg($nomphoto); 


$largeur_source = imagesx($source);
$hauteur_source = imagesy($source);
$largeur_destination = imagesx($destination);
$hauteur_destination = imagesy($destination);



$destination_x = 0;
$destination_y =  ($hauteur_destination / 1.5) - ($hauteur_source / 2);


imagecopymerge($destination, $source, $destination_x, $destination_y, 0, 0, $largeur_source, $hauteur_source, 60);


imagejpeg($destination);

我无法从 logo.php

加载图片

logo.php 代码

$imgPng = imagecreatefrompng("logo24.png");
imagealphablending($imgPng, true);
imageSaveAlpha($imgPng, true);

header("Content-type: image/png");
imagePng($imgPng); 

我想为我的 png-24 图像添加版权。 logo.php 工作正常,我可以得到图片,但是当我将它与 imagecreatefrompng 一起使用时,它不起作用。

我尝试使用 imagecreatefrompng(file_get_contents('logo.php')); 但它也不起作用。 我想要的是把我的 png-24 版权图像放在我的 jpg 上(以保持透明度) 你们有什么解决办法吗?

【问题讨论】:

  • 不是问题...它是 imagecopymerge() 不适用于 png-24。 imagecopy() 做到了!
  • 自己解决这个问题做得很好:) 如果可以,请将解决方案写为答案并将其标记为已解决。
  • 我将您的解决方案移至社区 wiki 答案。

标签: php png content-type imagecreatefrompng


【解决方案1】:

OP 的解决方案。

必须使用 imagecopy()

,而不是使用 imagecopymerge()
imagecopy($destination, $source, $destination_x, $destination_y, 0, 0, $largeur_source, $hauteur_source);

然后就不需要logo.php 代码了。只需加载 png-24 图像。

【讨论】:

    猜你喜欢
    • 2011-07-07
    • 2017-02-05
    • 2016-11-09
    • 2015-07-08
    • 1970-01-01
    • 2012-07-18
    • 1970-01-01
    • 2020-03-17
    • 2012-02-06
    相关资源
    最近更新 更多