Possible to scale an image directly to specific pixel dimensions?

I don't see such an API, so probably not... but I have overlooked stuff before!

Can I directly scale an image to, say, exactly 57x37 pixels? Instead of scaling by a proportion?

This indirect method seems to work, but I know internally it's using not-quite-integer pixel sizes. No biggie, but I'd do it more directly if I could.

w, h = originalImage:getSize()
resizedImage = originalImage:scaledImage(57 / w, 37 / h)

How about?

w, h = originalImage:getSize()
resizedImage = originalImage:scaledImage(math.ceil(57 / w), math.ceil(37 / h))

Or more optimally:

local ceil <const> = math.ceil
w, h = originalImage:getSize()
resizedImage = originalImage:scaledImage(ceil(57 / w), ceil(37 / h))

Thanks--I'm just wondering if I'm missing something where the SDK can size an image directly, without the manual division step.

Luckily the indirect method has worked for me, without floor or ceil needed. Good to keep options in mind if it ever fails though!

1 Like

If you want to add that method to playdate.graphics.image yourself, nothing's stopping you!

(Except that we could add a method with the same name in a future SDK release, so you might want to name yours with a prefix to be extra safe. But it's totally fine to do this.)

1 Like