I tried to post an image to the forum earlier, but it wouldn’t let me and said the image size was too big. So I wrote this to crop or reduce the size of an image. Just select an image in the readImage line and run the code. Put your finger on any of the lines and slide it to crop your image. To fine tune the positions, tap near a line either above/below, right/left to move it 1 pixel in that direction. At the top of the screen is the width and height value of the cropped image. When your ready to crop, tap the > upper left screen to show the parameter window. Tap copy to show you what the cropped image will look like. If you need to fine tune it, tap clear and reposition the lines. If it’s OK, tap save and it will be in the Dropbox folder with the name newImg. If you don’t see the newImg in the Dropbox folder, you need to exit the code. Nothing too fancy, just something I thru together.
-- image crop
viewer.mode=FULLSCREEN
function setup()
img=readImage(asset.documents.Dropbox.jor)
parameter.action("Copy",copy)
parameter.action("Clear",clear)
parameter.action("Save",save)
stroke(255)
strokeWidth(2)
iw=img.width//1
ih=img.height//1
l=(WIDTH-iw)//2
b=(HEIGHT-ih)//2
left=(WIDTH*.3)//1
right=(WIDTH*.7)//1
top=(HEIGHT*.7)//1
bottom=(HEIGHT*.3)//1
fill(255)
end
function draw()
background(0)
if newImg~=nil then
sprite(newImg,WIDTH/2,HEIGHT/2)
else
sprite(img,WIDTH/2,HEIGHT/2)
line(left,0,left,HEIGHT)
line(right,0,right,HEIGHT)
line(0,top,WIDTH,top)
line(0,bottom,WIDTH,bottom)
end
text("Width "..right-left.." Height "..top-bottom,WIDTH/2,HEIGHT-30)
end
function touched(t)
if t.state==BEGAN then
if math.abs(t.x-left)<50 then
if t.x<left then
left=left-1
else
left=left+1
end
end
if math.abs(t.x-right)<50 then
if t.x<right then
right=right-1
else
right=right+1
end
end
if math.abs(t.y-top)<50 then
if t.y<top then
top=top-1
else
top=top+1
end
end
if math.abs(t.y-bottom)<50 then
if t.y<bottom then
bottom=bottom-1
else
bottom=bottom+1
end
end
end
if t.state==CHANGED then
if math.abs(t.x-left)<50 then
left=left+t.deltaX
if left>=right then
left=right-10
end
end
if math.abs(t.x-right)<50 then
right=right+t.deltaX
if right<=left then
right=left+10
end
end
if math.abs(t.y-top)<50 then
top=top+t.deltaY
if top<=bottom then
top=bottom+10
end
end
if math.abs(t.y-bottom)<50 then
bottom=bottom+t.deltaY
if bottom>=top then
bottom=top-10
end
end
end
if t.state==ENDED then
left=left//1
right=right//1
top=top//1
bottom=bottom//1
end
end
function copy()
output.clear()
print("Image copied")
newImg=img:copy((left-l)//1,(bottom-b)//1,(right-left)//1,(top-bottom)//1)
end
function save()
output.clear()
if newImg~=nil then
print("Image saved")
saveImage(asset.documents.Dropbox.."newImg",newImg)
else
print("Copy image first")
end
end
function clear()
output.clear()
print("Image cleared")
newImg=nil
end