正确使用 imageapi_image_overlay 吗?
我想使用 imagecache Actions 模块来创建图像叠加。用户应该上传一张图像,我想缩放和裁剪它,然后在上面覆盖一个透明的 PNG。
我已经安装了 drupal 6 和 ImageCache 和 ImageCache 操作 模块。 ImageCache Actions 定义了imageapi_image_overlay
函数。
我创建了一个名为 590x160_Newsletter
的 ImageCache 预设来缩放和裁剪图像。
图像工具是 GD
这是我想要做的:用户上传图像。该图像使用 ImageCache 预设进行缩放和裁剪。然后我想用图像(具有透明度的PNG)覆盖它。我无法选择将其添加到预设中,因为它取决于节点中的一些其他设置,即我想要使用的覆盖图像。
比例和裁剪效果很好,但调用 imageapi_image_overlay
后的 $image2
仍然相同(相同的路径,相同的图像),尽管它显示“成功”。但它应该像 API 参考 说
这是一个测试代码
/* 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\" />";
I want to use imagecache Actions module to create image overlays. The user should upload one image and I want to scale and crop it and then overlay a transparent PNG over it.
I have installed drupal 6 and ImageCache and ImageCache Actions modules. ImageCache Actions defines the imageapi_image_overlay
function.
I have created a ImageCache Preset with the name 590x160_Newsletter
to scale and crop the image.
Image Tool is GD
Heres what I want to do: User uploads an image. This Image is scaled and cropped with the ImageCache preset. Then I want to overlay it with an image (PNG with transparency). I cannot choose this to be in the preset, because it depends on some other settings in the node, which overlay image I want to use.
The scale and crop does work good, but the $image2
after calling imageapi_image_overlay
is still the same (same path, same image) though it says 'success'. But it should be altered like the API reference says
Here is a test code
/* 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\" />";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现:
您必须自己保存图像:
对象
$image2
有两个重要元素:$image2->source
这是原始图像的文件名$image2->resource
是文件资源,即PHP图像资源。该资源在此过程中发生更改,但不会保存到磁盘。imagejpeg ($image2->resource, $images2->source);
会将文件保存为同名的 JPG。I found out:
You have to save the image for yourself:
The Object
$image2
has two significant elements:$image2->source
which is the filename of the original image and$image2->resource
which is the file resource, that is the PHP image resource. This resource is altered in the process, but not saved to disk.imagejpeg ($image2->resource, $images2->source);
will save the file as JPG under the same name.