0

It's late here and my brain doesn't work as it should so...

I have an image 244x175 pixels and I want to scale it in order to fit in an 125mm area for a PDF I am generating by using www.tcpdf.org.

How many much I have to scale it in order to fit correctly?

Thanks in advance

Mark Storer
  • 15,672
  • 3
  • 42
  • 80
chchrist
  • 18,854
  • 11
  • 48
  • 82
  • 2
    It depends. How big does the image come out (in mm) if you just don't scale it at all? – Sophie Alpert Feb 21 '11 at 01:39
  • 1
    Is the target space 125mm square, or just 125mm in one dimension with as much space available as needed in the other? – meklarian Feb 21 '11 at 01:41
  • The pixel dimensions of the original image are irrelevant to how you want to scale the image, unless you want to maintain its proportions. Do you need to stretch to fit a 125mmx125mm area, or do you need to maintain the original proportions. – Mark Storer Feb 21 '11 at 18:21

2 Answers2

1

Pixels and mm are not the same units. PDF documents don't work in pixels so it doesn't matter. You just place the image at the right coordinates and specify a width in mm (which you have, 125mm, right?)

However, if you're asking how to fit it within a specific constraint, as where the width AND the height is 125mm, it kind of depends what you want to happen. Possible outcomes are:

the image is placed in a correct height but the width could be bigger or smaller than the height constraints. what you want to happen at that point depends on if you want the image to become cropped or stretched or even to be displayed bigger then the width constraints.

and if it's ok that it's bigger on the width, you need to decide if you want the width of the image to offset the X coordinates of the image itself so that the image becomes centered, or whatever.

and then it's the same for if you want it to depend on the constraints in the width:..

so you have multiple options on how you want this thing to behave (if I understand you correctly)

arnorhs
  • 10,383
  • 2
  • 35
  • 38
1

Okay. PDF uses points. 1 point is 1/72 of an inch. 125mm = 4.921 inches. 4.921 * 72 = 354.312 points. Fractional points are just fine.

And it looks like TCPDF abstracts much of the work away unless you do some serious digging, which you don't need to do.

According to the docs for Image, all you need to do is specify the dimension you want to fit, and it'll scale the other proportionally:

// draw an image that is 125mm wide, and scaled to whatever height is needed
// to maintain the same proportions
TCPDF::image($path, $xloc, $yloc, 
             354.321, 0, ''/*no link*/,
             ''/*use path extension for type*/,
             true /*resize*/ ); // and let the rest default

I've never used TCPDF (or PHP for that matter) myself, but according to the docs, some variation on that will work.

Mark Storer
  • 15,672
  • 3
  • 42
  • 80