Re: Re: Images and PDF:API2

"Mr. Shawn H. Corey" <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.pdfapi2
Message-ID <[email protected]>
spinningwebz2002 wrote:
> Thanks for the tip. Do you know how the scale option works? Or maybe 
> if I tell you want I want to happen you can give me some pointers
> 
> I want center an image and have the height be a particular size and 
> the width be proportional to that. If it is possible I would like to 
> crop the extra width if any, but I an always draw a white box over 
> the extra width if need be. 

To calculate the scaling factor, you need to know how many pixels wide (or high) your image is and how wide, in points, you want the result.

Example 1: a 4x6 photo at 300 dpi.

  $image_width = 4 * 300;  # 4 inches at 300 dpi
  $result_width = 4 * 72;  # 4 inches at 72 points per inch
  $scale = $image_width / $result_width;

Example 2: a PNG of 1280 pixels wide to be shown sideways at 10 inches wide.

  $image_width = 1280;
  $result_width = 10 * 72;  # 10 inches at 72 points per inch
  $scale = $image_width / $result_width;

Example 3: a 3x2 inch photo at 150dpi to be shown at twice its size

  $image_width = 3 * 150;  # 3 inches at 150 dpi
  $result_width = 6 * 72;  # 6 inches at 72 points per inch
  $scale = $image_width / $result_width;


-- 
Just my 0.00000002 million dollars worth,
  Shawn

"For the things we have to learn before we can do them, we learn by doing them."
  Aristotle
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.