我想使用imagecache Actions模块来创建图像叠加。用户应该上传一张图片,我想缩放并剪裁,然后在上面覆盖透明的PNG。正确使用imageapi_image_overlay?
我已经安装了drupal 6和ImageCache和ImageCache 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\" />";