doulu5109
2011-11-29 08:36 阅读 60
已采纳

正确使用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 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.

    点赞 评论 复制链接分享

相关推荐