Resizing ImageData

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
User avatar
Dr.Tyler O.
Citizen
Posts: 58
Joined: Tue Jul 29, 2014 9:17 am
Location: United States

Resizing ImageData

Post by Dr.Tyler O. »

I've been looking everywhere and haven't found any information regarding it. I'm looking to resize imagedata and then encode it, not draw it on the screen. Can Love2D accomplish this?
Any topic I have ever posted that I felt did not require a .love file, although they were requested, never required one so I would appreciate if you did not ask me to supply one unless you think that I am ignorant for not doing so.
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: Resizing ImageData

Post by arampl »

You can create new empty ImageData with needed w&h, then use "paste" method from source ImageData.
If you want to scale source image to new size then create canvas with needed w&h, scale and draw image to it, then get ImageData from it.
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Resizing ImageData

Post by zorg »

Or, if you want to forego doing anything with the gpu pipeline, then you can also write a function that accepts an imagedata, and two numbers representing the output dimensions (and maybe another for the scaling function, or just hardcode one), and you can calculate the resulting pixels using any number of scaling algorithms that exist already. Nearest neighbor would be probably the simplest.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
Evine
Citizen
Posts: 72
Joined: Wed May 28, 2014 11:46 pm

Re: Resizing ImageData

Post by Evine »

Needed something similar myself so I wrote it now :awesome:
Now the down-sampling is rather poor. But it works.

Code: Select all

local function createThumbnail(fileName,scale)
	scale = scale or 1
	local img = love.graphics.newImage(fileName)
	local canvas = love.graphics.newCanvas(img:getWidth()*scale , img:getHeight()*scale)
	love.graphics.push("all")
	local wasCanvas = love.graphics.getCanvas()
	love.graphics.setCanvas(canvas)
	canvas:clear()
	
	love.graphics.draw(img,0,0,0,scale)
	love.graphics.pop()
	love.graphics.setCanvas(wasCanvas)
	local imageData = canvas:getImageData()
	return imageData
end
Artal, A .PSD loader: https://github.com/EvineDev/Artal
Post Reply

Who is online

Users browsing this forum: No registered users and 153 guests