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开发者_StackOverflow 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
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.
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)
精彩评论