Is there a way to resize an overlay image, preferably in percent of the canvas? For example I am using an alpha trans .png to vignette pictures with the imagecache action Overlay, but I would like to allow for different height images by stretching the .png to 100% x 100% of the canvas. Any ideas?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

eojthebrave’s picture

If I understand what you're trying to to I think you can use the imagecache "Scale" action and click the "Allow upsizing" checkbox. This will allow you to take images that are smaller than your desired dimensions and upscale them to the correct size and allow images larger than your desired dimensions to be scaled down.

drewish’s picture

Project: ImageCache » ImageCache Actions
Version: 6.x-2.x-dev »

might be better to ask over in this queue.

dman’s picture

stretching images generally looks horrible.
If you want a vignette thing , perhaps imagecache_scale9 is a better result.
I don't think we'll be adding resize to overlays

dman’s picture

Status: Active » Closed (won't fix)

I can't see this happening.

raintonr’s picture

Category: support » feature
Status: Closed (won't fix) » Active

+1 for this as I'd find it very useful:

- Have an overlay resized (including upscale if that's appropriate) to fill one (preserving the aspect ratio of the overlay) or both (ignoring the aspect ratio of the overlay) of the dimensions of the target image.

Could this be an option on the canvasactions_file2canvas action?

The reason for this is that sometimes you want a single rule to watermark images of any size. Clearly when working on different images, if the overlay isn't resized to match the target this could result in a watermark that is hardly visible (watermark too small for image) or too large (watermark 'overflows' image).

raintonr’s picture

Version: » 6.x-1.7
Status: Active » Needs review
FileSize
1.83 KB

Turned out this was simple enough. Please see enclosed patch.

I added a 'Scale' checkbox to the 'Overlay (watermark)' action which is off by default (preserves original action).

This patch was made against v6.x-1.7 packaged 2010-05-25.

bdone’s picture

Patch #6 works for me.

When upscaling the overlay, I'd prefer to use imageapi_image_resize() (to ignore aspect ratio).

Perhaps the UI could allow a choice?

NaX’s picture

Version: 6.x-1.7 » 6.x-1.x-dev
Component: Miscellaneous » Canvas Actions Module

Worked great for me, this actually prevents a PHP error for me when the watermark is larger than the canvas. As I don't have control over the size of the images my client uploads, this is a nice workaround/fix for me.

Error:

ImageMagick reported error code 1. Message: convert: invalid argument for option `+-6+77': -geometry. in /usr/www/sites/all/modules/imageapi/imageapi_imagemagick.module on line 235.

When I used a smaller watermark that was much smaller than the image, the positioning was off. To correct this the only thing I changed was for it to not up scale.

EG: imageapi_image_scale($overlay, $image->info['width'], $image->info['height'], FALSE);

I actually think this imageapi_image_scale() call should be the default if the overlay is larger than the image and the only option should be if it should up scale when the overlay is smaller.

christian death’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev

Work perfect.

But for Drupal 7 change
imageapi_image_scale($overlay, $image->info['width'], $image->info['height'], TRUE);
to
image_scale($overlay, $image->info['width'], $image->info['height'], TRUE);

RobW’s picture

Chiming back in, I obviously went a different way (4 side specific overlays) for the project I was working on a couple months ago, but am happy that this issue got some love. Thanks for writing a working patch, will test as soon as I have some time outside of client work.

christian death’s picture

Priority: Normal » Major
Status: Needs review » Needs work
fietserwin’s picture

Priority: Major » Normal

Canvas actions and differently sized images do not cooperate nicely, certainly not when using Imagemagick. However, I think we should better support this. Certainly for image masks like blurred edges it can be expected that one wants to resize the mask first to the current image size before applying it.

Patches against the latest 7.x-1.dev are welcome and will be considered.

fietserwin’s picture

Status: Needs work » Postponed

Postponing until after the 7.x-1.0 release. I don't expect to see any patch here soon that:
- will implement it for imagemagick as well.
- will implement it for both underlay and overlay.

Patches that do the above remain welcome.

Ace Cooper’s picture

I'm working on a e-commerce catalog, that uses photoes of different sizes and proportions.
Naturally, I bumped into the issue of watermark scaling.
In my case the watermark was sometimes larger than the catalog images.

I've decided to add a 0-100% scaling for overlay image (watermark) in case you might need extra margins.
If you leave the Scale input empty - the overlay image shall have it's original dimensions.
Below is a patch against ImageCache Actions 7.x-1.x-dev dated 2012-Dec-05 (before/after).

UPD. The patch tested only for GD library. The scale of overlay (watermark) is relative to the canvas/underlay image.

dman’s picture

Assigned: Unassigned » Ace Cooper
Status: Postponed » Needs review

Cool. Patch reads well. Looks like it would be a good help.

fietserwin’s picture

Thanks for posting.

  • The percentage is with respect to the size of the image being processed, not the waternark itself. This is correct but should be mentioned in the description.
  • The aspect ratio is lost when the watermark is resized. This does not feel correct to me but I guess there are cases where it should be like that, but also cases where the aspect ratio should be kept. So I think this option also need a checkbox "maintain aspect ratio".
  • I think that the form default should be empty, not 100
  • I'm afraid that the image_scale as used here will not work with the way imagemagick builds up the command list. If so, this should be moved to GD specific processing.

As mentioned in #13, I would also like to see the patch cover the underlay effect and support the imagemagick toolkit.

Ace Cooper’s picture

I agree, that my patch only solves a partial usecase.
In my catalog the images have low resolution and dimensions, so the downscaling of watermark was necessary.
But in case the underlay images are much larger than the watermark - the overlay will become grainy after upscaling.
Hence I also have to add an option to limit overlay upscaling above original dimensions (or other limit like 2x, 3x, etc.)

The proportions of the watermark are not lost after scaling (there is a "TRUE" parameter to preserve the ratio).
You can check it yourself here, notice different proportions of most pictures in the gallery.

As for ImageMagick - I have no idea of the ways it is different from GD.
I can make no judgement on code compatibility, so I shall trust fietserwin on the matter.
I kindly ask anyone better versed with ImageMagick to take a look at this patch.

fietserwin’s picture

Status: Needs review » Needs work

- OK, you are right with the aspect ratio, While reviewing, I just noted that the width and height were calculated using different values.
- Imagemagick is indeed quite different. If you can refactor that part by moving it into the GD specific processing I will have a look at the Imagemagick processing.

Regarding additional optins:
- Do we still need that checkbox to preserver or not the aspect ratio?
- Do we need an option to limit upscaling?
- Do we need a repeat option?

Or do we start with a simple version and see what requests we do get?

dman’s picture

I think
* always preserve the aspect ratio. Anything else is super-ugly always.
* either don't limit upscaling at all, or expose the option as a checkbox. If someone said they want the watermark 20% of the image and uploads even a giant image, they should still get that.
* repeat will be noce, but a different issue. You need to add spacing and tiling options for that. New feature request.

And yes, the default should be empty/unset to preserve the 'normal' behavior, and not jump to completely covering everything 100% :-)

ttkaminski’s picture

Updated the patch in #14 with the following:

- Always keep aspect ratio. The overlay is scaled based on the widths of the images.
- Fixed image_imagemagick_overlay() to properly apply the new overlay size

ttkaminski’s picture

Another tweak:
- Null out the default overlay scale so that default action isn't changed (ie. overlay isn't scaled)

thijsvdanker’s picture

Status: Needs work » Needs review
FileSize
2.95 KB

Rerolled the patch from #21 and changed the $image-ops to use $realPath instead of $layer->source.

candelas’s picture

patch #22 working
Thank you all :)

MmMnRr’s picture

Patch from comment #22 worked for me.
Thank you!

  • fietserwin committed 07ed576 on 7.x-1.x
    [#760438] by raintonr, Ace Cooper, ttkaminski, thijsvdanker, fietserwin...
fietserwin’s picture

Assigned: Ace Cooper » Unassigned
Status: Needs review » Fixed

Committed this feature. I added some form validation, additional help and removed the ImageMagick support for now, that resized the source, not the overlay. I will look at that shortly.

Thanks all, as I found it hard to credit just one of you as the author, I did not credit any of you as author.

  • fietserwin committed c596339 on 7.x-1.x
    [#760438] by fietserwin: Resize Overlay / Watermark for ImageMagick.
    
fietserwin’s picture

That was not too difficult: http://www.imagemagick.org/Usage/layers/#composite, not -resize but -geometry was to be used.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.