Post without Account — your post will be reviewed, and if appropriate, posted under Anonymous.

RT 98545 - formimage() allow separate x and y scaling?

  • 2 Replies
  • 754 Views
*

Offline Phil

  • Global Moderator
  • Sr. Member
  • *****
  • 356
    • View Profile
RT 98545 - formimage() allow separate x and y scaling?
« October 21, 2016, 03:54:05 PM »
Subject:    formimage() allow separate x and y scaling?
Date:    Tue, 02 Sep 2014 11:50:13 -0400
To:    bug-PDF-API2 [...] rt.cpan.org
From:    Phil M Perry

PDF::API2 v2.022   Perl 5.16.3  Windows 7   severity: Wishlist

In Content.pm's formimage() method, there is a parameter for scaling. It affects both the x and y scaling. Perhaps an optional parameter could be added to be a separate scale-y (with the original parameter becoming scale-x)?
#
Subject:    [rt.cpan.org #98545]
Date:    Mon, 25 Jan 2016 10:05:39 -0500
To:    bug-PDF-API2 [...] rt.cpan.org
From:    Phil M Perry

Be aware that scaling an image by different factors in the x and y dimensions will result in distortion. Can anyone think of any legitimate use for such a distorted image? If it's a relatively small difference in scale factors, the resulting image might better fit the allotted space, without distortion being readily apparent. Anyway, the default usage would still be a single scale factor, applied to both x and y, and thus would not break any existing code.
#
Wed Feb 17 15:52:21 2016 steve [...] deefs.net - Correspondence added

This doesn't seem to be worth the effort of adding (you've already argued against it in your follow-up comment).

If someone has a real-world use case for it and contributes code and tests, then this can be revisited.
#
Wed Feb 17 15:52:21 2016 The RT System itself - Status changed from 'new' to 'open'
#
Wed Feb 17 15:52:22 2016 steve [...] deefs.net - Status changed from 'open' to 'rejected'
#
Subject:    [rt.cpan.org #98545]
Date:    Thu, 18 Feb 2016 16:25:05 -0500
To:    bug-PDF-API2 [...] rt.cpan.org
From:    Phil M Perry

I wasn't really arguing against it, so much as pointing out that it would probably only be useful for minor stretching in one direction or the other. Nevertheless, unless someone comes up with a crying need for it, it can probably be left in the reject pile for the time being.

*

Offline Phil

  • Global Moderator
  • Sr. Member
  • *****
  • 356
    • View Profile
Re: RT 98545 - formimage() allow separate x and y scaling?
« Reply #1: November 14, 2016, 08:42:59 PM »
Added in 3.001

It was such a trivial change to add that I went ahead and did it:

  • No scale given: use 1 and 1.
  • One scale factor given: use for both X and Y.
  • (New) Two scale factors given: they are separately for X direction and Y direction.

Since most images don't look that good when scaled differently in X and Y, please try to keep the two scale factors fairly close to each other. The purpose of having this ability is to make minor distortions to an image to better fill an allotted space.

*

Offline Phil

  • Global Moderator
  • Sr. Member
  • *****
  • 356
    • View Profile
Re: RT 98545 - formimage() allow separate x and y scaling?
« Reply #2: May 01, 2017, 11:43:10 AM »
Update for 3.003 release:

I have found that image_* calls and barcode calls produce image objects with very different scaling characteristics. Images are basically dimensionless, and need to be multiplied (scaled, in the transform matrix) by height and width to get to the desired size in points. On the other hand, barcodes appear to be already in points, and require scale factor(s) of close to 1. Adding $img->width() and $img->height() multipliers in formimage greatly overscales barcodes, while leaving the scale at 1 causes images to be displayed as about 1 pixel square. To minimize confusion, images should be given scale factors equal to the width and height (times any overall scaling), while barcodes should be given scale factors of around 1. This avoids having to pre-scale barcodes to 1/width and height values (to be backed out by multiplying by width and height within formimage()).

See the updated Content.pl and BarCode.pl examples for examples.