lib/sogoumap2pdf/image_to_pdf.rb in sogoumap2pdf-0.1.0 vs lib/sogoumap2pdf/image_to_pdf.rb in sogoumap2pdf-0.2.0

- old
+ new

@@ -99,11 +99,11 @@ pgimg=big_img_crop(j*(@page_width-@page_overlap), (rows-1-i)*(@page_height-@page_overlap),@page_width,@page_height) # pgimg=big_image.crop(j*(@page_width-@page_overlap), # i*(@page_height-@page_overlap),@page_width,@page_height,true) - pgimg.write("itptmp#{@link_end}") { self.quality = 70 } + pgimg.write("itptmp#{@link_end}") { self.quality = 100 } @pdf.add_image_from_file("itptmp#{@link_end}",0,0) ss = PDF::Writer::StrokeStyle.new(4,:cap=>:round) @pdf.stroke_style ss if j>0 then @pdf.add_internal_link("map part #{i},#{j-1}",0,@page_height/2, @@ -190,15 +190,20 @@ else resimg=ci.mosaic end #crop #map2pdf.rb:339:in `crop!': bignum too big to convert into `long' (RangeError) - x_string,y_string=resimg.density.split("x") - resx=x_string.to_i - resy=y_string.to_i - resimg.crop!(SouthWestGravity,resx<@page_width?resx:@page_width,resy<@page_height?resy:@page_height) - resimg.write("itptmp#{@link_end}"){ self.quality = 70 } + resx=@tumb_x*g.npx + resy=@tumb_y*g.npy + + p "front_page size" + p resx + p resy + resx=@page_width if resx>@page_width + resy=@page_height if resy>@page_height + resimg.crop!(SouthWestGravity,resx,resy) + resimg.write("itptmp#{@link_end}"){ self.quality = 100 } @pdf.add_image_from_file("itptmp#{@link_end}",0,0) ss = PDF::Writer::StrokeStyle.new(2) @pdf.stroke_style ss for i in 1...cols @pdf.line(i*@page_width/cols,0, @@ -216,9 +221,92 @@ j*@page_width/cols, @page_height-i*@page_height/rows, (j+1)*@page_width/cols, @page_height-(i+1)*@page_height/rows) end end end + def front_page_only(g) + size_x=@big_img_width + size_y=@big_img_height + # calculate the number of requred rows and columns + cols=(size_x-@page_overlap)/(@page_width-@page_overlap) + rows=(size_y-@page_overlap)/(@page_height-@page_overlap) + + ci=ImageList.new # image list to hold results + page=Rectangle.new( 0, 0, 0, 0) + @g=g + for i in 0... g.npx + p "resizing #{i} j" + for j in 0...g.npy + picture_file_name="~/.sogoumap/0/"+ [g.resource_type,g.resource_level,((g.start_link_x+i)/200).to_s,((g.start_link_y+j)/200).to_s].join("/")+"/"+(g.start_link_x+i).to_s+"_"+(g.start_link_y+j).to_s+g.link_end + picture_file_name=File.expand_path(picture_file_name) + if File.exist?(picture_file_name) && File.size(picture_file_name)!= 0 then + tumb=ImageList.new.read(picture_file_name)[0] # image list to hold results + + path_file_name="~/.sogoumap/0/"+ ["179",g.resource_level,((g.start_link_x+i)/200).to_s,((g.start_link_y+j)/200).to_s].join("/")+"/"+(g.start_link_x+i).to_s+"_"+(g.start_link_y+j).to_s+".PNG" + path_file_name=File.expand_path(path_file_name) + if g.satellite_path && File.exist?(path_file_name) && File.size(path_file_name)!=0 then + path_tumb=ImageList.new.read(path_file_name)[0] # image list to hold results + tumb.composite!(path_tumb, 0, 0, OverCompositeOp) + end + #resize each to tumb + tumb.resize!(@tumb_x,@tumb_y) + #append tumb + ci << tumb + #update page + page.x=i*@tumb_x + page.y=(g.npy-1-j)*@tumb_y + ci.page=page + else + end + end + end + #mosaic + if ci.length==0 then + p "@tumb_x,@tumb_y" + p @tumb_x + p @tumb_y + p "g.npx,g.npy" + p g.npx + p g.npy + p "#{g.npx*@tumb_x}x#{g.npy*@tumb_y}" + ## can't work + resimg=ImageList.new.read("null:white") { self.size = "#{g.npx.to_i*@tumb_x.to_i}x#{g.npy.to_i*@tumb_y.to_i}"} + else + resimg=ci.mosaic + end + #crop + #map2pdf.rb:339:in `crop!': bignum too big to convert into `long' (RangeError) + resx=@tumb_x*g.npx + resy=@tumb_y*g.npy + p "front_page size" + p resx + p resy + resx=@page_width if resx>@page_width + resy=@page_height if resy>@page_height + resimg.crop!(SouthWestGravity,resx,resy) + resimg.write("itptmp#{@link_end}"){ self.quality = 100 } + @pdf.add_image_from_file("itptmp#{@link_end}",0,0) + ss = PDF::Writer::StrokeStyle.new(2) + @pdf.stroke_style ss + for i in 1...cols + @pdf.line(i*@page_width/cols,0, + i*@page_width/cols,@page_height).stroke + end + for i in 1...rows + @pdf.line(0,i*@page_height/rows, + @page_width,i*@page_height/rows).stroke + end + # for i in 0...rows + # for j in 0...cols + # p "adding #{i} #{j} link in front page" + # p Time.now + # @pdf.add_internal_link("map part #{i},#{j}", + # j*@page_width/cols, @page_height-i*@page_height/rows, + # (j+1)*@page_width/cols, @page_height-(i+1)*@page_height/rows) + # end + # end + end + def save(save_file) @pdf.save_as(save_file) end end end