Is it possible to set the size of an image?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
ForeverDevv
Prole
Posts: 9
Joined: Sat Sep 13, 2014 10:20 pm

Is it possible to set the size of an image?

Post by ForeverDevv »

I want to create an image and edit it's size (I don't want to use scale factor, I want to set it to a certain size in pixels)

Is this possible?
User avatar
Ortimh
Citizen
Posts: 90
Joined: Tue Sep 09, 2014 5:07 am
Location: Indonesia

Re: Is it possible to set the size of an image?

Post by Ortimh »

I think it impossible to change the size of an image within LÖVE. But using scale will do like you want to:

Code: Select all

function setImageSize(image, x, y)
	return x / image:getWidth(), y / image:getHeight()
end
Example, if your image dimensions is 64 x 64 pixels then you want to resize it to 32 x 32 pixels:

Code: Select all

local image = love.graphics.newImage("image.png")

love.graphics.draw(image, 0, 0, 0, setImageSize(image, 32, 32))
setImageSize function returns 0.5 for both scale X and Y.
ForeverDevv
Prole
Posts: 9
Joined: Sat Sep 13, 2014 10:20 pm

Re: Is it possible to set the size of an image?

Post by ForeverDevv »

Ah, it worked.

Thank you very much!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 3 guests