function rand(x) return math.random(0, x-1) end w, h = img.width, img.height if w==1 and h==1 then return end m = w-1 r = rand(m*(h-1)-1) cw = r%m+1 ch = math.floor(r/m)+1 cx = rand(w-cw) cy = rand(h-ch) return "Random crop: "..cw..", "..ch..", "..(cx+cw)..", "..(cy+ch)