doulu5109 2011-11-29 08:36
浏览 61
已采纳

正确使用imageapi_image_overlay?

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) . "
";

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

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

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

1条回答 默认 最新

  • dtczp02204 2011-11-29 09:34
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办