2011-11-29 289 views
0

我想使用imagecache Actions模块来创建图像叠加。用户应该上传一张图片,我想缩放并剪裁,然后在上面覆盖透明的PNG。正确使用imageapi_image_overlay?

我已经安装了drupal 6和ImageCacheImageCache Actions模块。 ImageCache操作定义了imageapi_image_overlay函数。

我创建了名称为590x160_Newsletter的ImageCache预设来缩放和剪裁图像。

图像工具是GD

继承人是我想做的事:用户上传的图像。该图像被缩放并用ImageCache预设进行裁剪。然后我想叠加一个图像(具有透明度的PNG)。我不能选择它在预设中,因为它取决于节点中的一些其他设置,我要使用哪个叠加图像。

规模和作物确实很好,但拨打imageapi_image_overlay后的$image2仍然是一样的(相同的路径,相同的图像),虽然它说'成功'。但是应该改变像API reference

下面是测试代码

/* PHP */ 
require_once './includes/bootstrap.inc'; 
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); 

print "<body style=\"background: lightgreen\">"; 
$path = "path/to/source/image.jpg"; 
$opath = "path/to/overlay/image.png"; 
print '<xmp>'; 
$image = imageapi_image_open($path); 
print '$image: ' . print_r($image,1) . "\n"; 

$image2 =imageapi_image_open(imagecache_create_path('590x160_Newsletter', $path)); 
print '$image2: ' . print_r($image2,1) . "\n"; 

$overlay = imageapi_image_open($opath); 
print imageapi_image_overlay($image2, $overlay, 0, 0, 100, TRUE) ? "success\n" : "failure\n"; 

print '$image2 after: ' . print_r($image2,1) . "\n"; 
print '$overlay: ' . print_r($overlay,1) . "\n"; 
print '</xmp>'; 
print "<img src=\"$image->source\" />"; 
print "<img src=\"$image2->source\" />"; 
print "<img src=\"$overlay->source\" />"; 

回答

0

我发现:

你必须保存图像自己:

的对象$image2有两个重要元素:$image2->source,它是原始图像的文件名,$image2->resource是文件资源,即PHP图像资源。此资源在过程中被更改,但未保存到磁盘。

imagejpeg ($image2->resource, $images2->source);将文件另存为JPG下同名。