Skip to content

Commit

Permalink
split Pixbuf loader process.
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Dec 22, 2010
1 parent 7cb9b6d commit 8007cc7
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,27 @@ def prepare_real_name(name)
end
end

def load_pixbuf(info)
screen_name = info[:screen_name]
profile_image_url = info[:profile_image_url]
*profile_image_url_components = profile_image_url.split(/\//)
profile_image_last_component = profile_image_url_components.last
profile_image_url_components[-1] =
u(profile_image_last_component.gsub(/_normal\.([a-zA-Z]+)\z/, '.\1'))
profile_image_url = profile_image_url_components.join("/")

extension = $1
image_data = cache_file("images", "#{screen_name}.#{extension}") do
open(profile_image_url, "rb") do |image_file|
image_file.read
end
end
loader = Gdk::PixbufLoader.new
loader.write(image_data)
loader.close
loader.pixbuf
end

def render_to_surface_big(surface, scale, paper, info, font)
margin = paper.width * 0.03
image_width = image_height = paper.width * 0.3
Expand Down Expand Up @@ -139,22 +160,7 @@ def render_to_surface_big(surface, scale, paper, info, font)
context.move_to(margin, paper.height - layout.pixel_size[1] - margin)
context.show_pango_layout(layout)

*profile_image_url_components = info[:profile_image_url].split(/\//)
profile_image_last_component = profile_image_url_components.last
profile_image_url_components[-1] =
u(profile_image_last_component.gsub(/_normal\.([a-zA-Z]+)\z/, '.\1'))
profile_image_url = profile_image_url_components.join("/")

extension = $1
image_data = cache_file("images", "#{screen_name}.#{extension}") do
open(profile_image_url, "rb") do |image_file|
image_file.read
end
end
loader = Gdk::PixbufLoader.new
loader.write(image_data)
loader.close
pixbuf = loader.pixbuf
pixbuf = load_pixbuf(info)
if pixbuf
context.save do
context.translate(paper.width - image_width - margin,
Expand Down

0 comments on commit 8007cc7

Please sign in to comment.