-- -- lua5.1 toDPI_panel.lua -- -- doug rice copyright September 2011 -- -- description - produces DPI pictures in a panel of 4 -- pictures in img_ip are prepared to DIP standard of 1400 wide x 1050 high with border -- pictures output to -- ./img_op -- and -- ./img_op/sm -- -- -- Add a panel feature that puts the last four images into a panel. -- -- 1400 x 1050 -- -- -- -- b [ a ] b [ a ] b = 2 a + 3 b -- b [ a ] b [ a ] b -- -- get dimensions for rectangle a -- work out if A is more portrate than frame. -- -- We need to map the image to the square. -- -- work out where a is -- require "gd" -- -- Sec 1.0 Functions -- -- capture dir /b *.jpg and pasted into string below. picsStr="" -- -- -- -- -- Picture is any dimension -- -- We want to fit an image to a canvas of 1400 : 1050 -- wantHeight,wantWidth -- allow for border so fit img into toDPI -- imgX => toX -- imgY => toY -- -- if ( wantY / wantX ) > ( imgY / imgX ) then portrait. -- if ( wantY / wantX ) < ( imgY / imgX ) then landscape. -- -- picsA = {} fi = io.popen( "dir /b .\\img_ip\\*.jpg ") for i in fi:lines() do print( "+"..i ) print( "#picsA ",picsA ) picsA[ #picsA+1 ] = "./img_ip/" .. i end cnt = #picsA print( "cnt" ,cnt ) wantWidth = 1000 wantHeight = 1000 borderX = 70 borderY = borderX / wantWidth * wantHeight im = gd.createTrueColor( wantWidth , wantHeight ) color = im:colorAllocateAlpha( 0, 0, 0, 64) color2 = im:colorAllocateAlpha( 255, 255, 255, 64) white = im:colorAllocateAlpha( 255, 255, 255, 0 ) black = im:colorAllocateAlpha( 0,0,0,0 ) bcolor = im:colorAllocateAlpha( 0,128,128, 0 ) --bcolor = im:colorAllocateAlpha( 0,8,8, 0 ) red = im:colorAllocateAlpha( 255,0,0, 0 ) function prepareDPI2( x1, y1, x2, y2 ,offset ) im:rectangle(x1, y1, x2, y2, black ) -- padding background im:filledRectangle( x1, y1, x2, y2, bcolor ) -- rotate = true -- print( text, size, ang, filename, offset, wantWidth, wantHeight , position ) im_org_port = gd.createFromJpeg( picsA[ offset+1 ] ) imgX,imgY = im_org_port:sizeXY() rotate = ( imgY/imgX ) > 1 if ( rotate ) then print( "rotating....................." ) --gd.copyRotated(dstImage, srcImage, dstX, dstY, srcX, srcY, srcW, srcH, ang) --dstImage:copyRotated(srcImage, dstX, dstY, srcX, srcY, srcW, srcH, ang) im_org = gd.createTrueColor( imgY, imgX ) gd.copyRotated(im_org, im_org_port, imgY / 2, imgX/2, 0,0, imgX, imgY, -90) im_org_port=nil else im_org = gd.createFromJpeg( picsA[ offset +1 ] ) end w = x2 - x1 h = y2 - y1 imgX,imgY = im_org:sizeXY() if ( h/w ) < ( imgY/imgX) then -- image more portrate then destination - pad width scale = h / imgY padwidth = w - ( imgX * scale ) print( "portrate", scale , padwidth ) -- dstImage:copyResampled(srcImage, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH) im:copyResampled( im_org, x1 + padwidth/2 ,y1, 0,0, imgX * scale , y2 - y1 , imgX, imgY) else -- image more landscape than destination - pad height scale = w / imgX padheight = h- (imgY * scale) print( "landscape", scale , padwidth ) -- dstImage:copyResampled(srcImage, dstX, dstY, srcX, srcY, dstW*, dstH, srcW, srcH) im:copyResampled( im_org, x1,y1+padheight/2, 0,0, (x2 - x1) , imgY *scale, imgX, imgY ) end -- border around picture im:rectangle(x1, y1, x2, y2, black ) end function main() -- padding background im:filledRectangle( 0,0, wantWidth-0, wantHeight-0 , white ) -- b [ a ] b [ a ] b = 2 a + 3 b -- b [ a ] b [ a ] b -- top row ax = ( wantWidth -1 - 3 * borderX )/2 ay = ( wantHeight -1 - 3 * borderY )/2 x1 = borderX x2 = x1 + ax y1 = borderY y2 = y1 + ay print( x1,x2,y1,y2 ) prepareDPI2( x1, y1, x2, y2 , 0 ) x1 = x2 + borderX x2 = x1 + ax y1 = borderY y2 = y1 + ay print( x1,x2,y1,y2 ) prepareDPI2( x1, y1, x2, y2 , 1 ) -- bottom row x1 = borderX x2 = x1 + ax y1 = y2 + borderY y2 = y1 + ay print( x1,x2,y1,y2 ) prepareDPI2( x1, y1, x2, y2 , 2 ) x1 = x2 + borderX x2 = x1 + ax -- y1 = border y2 = y1 + ay print( x1,x2,y1,y2 ) prepareDPI2( x1, y1, x2, y2 , 3 ) os.execute("mkdir .\\img_op") im:jpeg( ".\\img_op\\panel.jpg", 85 ) end main()