-- -- 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. -- 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. -- -- wantWidth = 1400 wantHeight = 1050 border = 5 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,64,64, 0 ) bcolor = im:colorAllocateAlpha( 0,8,8, 0 ) red = im:colorAllocateAlpha( 255,0,0, 0 ) im:filledRectangle( 0,0, wantWidth-1, wantHeight-1 , white ) -- BBBBBBBBB -- B pp B pp B -- BBBBBBBBB function prepareDPI_panel( text, size, ang, filename111, offset, wantWidth, wantHeight, position ) -- position -- [ 1 ][ 2 ] -- [ 3 ][ 4 ] im_org = "" im_org = 1 im_org = nil -- rotate = true print( text, size, ang, filename, offset, wantWidth, wantHeight , position ) wantY = wantHeight-1 wantX = wantWidth-1 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 imgX,imgY = im_org:sizeXY() --[==[ rotate the incoming image ]==] -- portrait -- -- 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. -- -- -- work out toX wantY = wantHeight-1 wantX = wantWidth-1 border = 5 imgX,imgY = im_org:sizeXY() if ( ( wantY/wantX ) > ( imgY/imgX ) ) then print( " portrait -- ") -- background canvas -- im:filledRectangle( 0,0, wantWidth-1, wantHeight-1 , bcolor ) toHeight = (wantHeight/2) - border*3 toWidth = (wantHeight/2) /imgY*imgX - border*3 -- dstImage:copyResampled(srcImage, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH) if position == 0 then im:copyResampled(im_org, ( wantWidth-toWidth ) /4 + 0, border, 0,0, toWidth , toHeight , imgX , imgY ) end if position == 1 then im:copyResampled(im_org, ( wantWidth-toWidth ) /4 + wantWidth/2 , border, 0,0, toWidth , toHeight , imgX , imgY ) end if position == 2 then im:copyResampled(im_org, ( wantWidth-toWidth ) /4 +0 , border + wantHeight/2 , 0,0, toWidth , toHeight , imgX , imgY ) end if position == 3 then im:copyResampled(im_org, ( wantWidth-toWidth ) /4 + wantWidth/2 , border + wantHeight/2, 0,0, toWidth , toHeight , imgX , imgY ) end -- border -- im:filledRectangle( ( wantWidth-toWidth-border*2 ) /2 -1 ,0, (wantWidth+toWidth+border*2)/2-1, wantHeight-1 , white ) -- dstImage:copyResampled(srcImage, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH) -- im:copyResampled(im_org, ( wantWidth-toWidth ) /2 , border, 0,0, toWidth , toHeight , imgX , imgY ) -- im:rectangle( ( wantWidth-toWidth-border*2 ) /2 -1 ,0, (wantWidth+toWidth+border*2)/2-1, wantHeight-1 , red ) else print "landscape" -- landscape -- background canvas -- im:filledRectangle( 0,0, wantWidth-1, wantHeight-1 , bcolor ) toHeight = wantWidth/imgX*imgY - border*3 toWidth = wantWidth - border*3 -- border -- im:filledRectangle( 0, ( wantHeight-toHeight-border*2 ) /2 -1 , wantWidth-1,(wantHeight+toHeight +border*2)/2-1, white ) -- dstImage:copyResampled(srcImage, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH) -- im:copyResampled(im_org, border, (wantHeight-toHeight ) /2 , 0,0, toWidth,toHeight, imgX, imgY) if position == 0 then im:copyResampled(im_org, border, ( wantHeight-toHeight ) /2 , 0,0, toWidth/2,toHeight/2, imgX, imgY) end if position == 1 then im:copyResampled(im_org, border + wantWidth/2 , ( wantHeight-toHeight ) /2 , 0,0, toWidth/2,toHeight/2, imgX, imgY) end if position == 2 then im:copyResampled(im_org, border, ( wantHeight-toHeight ) /2 +wantHeight/2, 0,0, toWidth/2,toHeight/2, imgX, imgY) end if position == 3 then im:copyResampled( im_org, border + wantWidth / 2 , ( wantHeight-toHeight ) / 2 +wantHeight/ 2 , 0,0, toWidth/2,toHeight/ 2, imgX, imgY) end -- im:rectangle( 0, ( wantHeight-toHeight-border*2 ) /2 -1 , wantWidth-1, (wantHeight+toHeight +border*2)/2-1, red ) end im_org = nil -- force a garbage collect as it ran out of virtual memory without it. collectgarbage ( "collect" ) end function main() cnt = 0 for w in string.gmatch(picsStr, "%C+") do print("=="..w.."==") if string.len(w) > 0 then -- picsA[cnt] = "./APSC/"..w picsA[cnt] = "./"..w cnt = cnt + 1 end end 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 ) steps = cnt while( steps > 0 ) do steps = steps - 1 prepareDPI_panel( "", 10, 0 , 1000+steps, steps , 1400, 1050 , steps ) end im:sharpen( 20 ) print( filename ) filename = "./img_op/panel- -panel" im:jpeg( filename .. ".jpg", 85 ) end -- -- MAIN () -- os.execute("mkdir .\\img_op") main()