Skip to content

Commit

Permalink
Remove rmagick
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-kolb committed Sep 3, 2024
1 parent a2a949e commit 4e53267
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ gem 'mongoid', '~> 6.0'
gem 'rake'
gem 'require_all'
gem 'rest-client'
gem 'rmagick', '~> 2.16'
# gem 'rmagick', '~> 2.16'
gem 'rss'
gem 'rubocop', require: false
gem 'sinatra', '~> 2.1'
Expand Down
1 change: 0 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ GEM
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rexml (3.2.5)
rmagick (2.16.0)
rss (0.3.1)
rexml
rubocop (0.92.0)
Expand Down
8 changes: 4 additions & 4 deletions lib/io_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'json'
require 'rmagick'
# require 'rmagick'

module IoHelper
def write_json_file(filename, data)
Expand All @@ -9,9 +9,9 @@ def write_json_file(filename, data)
end

def write_png_image(filename, data)
image = Magick::Image.from_blob(data).first
image.format = 'PNG'
image.write(filename << '.png')
# image = Magick::Image.from_blob(data).first
# image.format = 'PNG'
# image.write(filename << '.png')
end

def to_filename(str)
Expand Down
82 changes: 41 additions & 41 deletions tasks/assets.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'rmagick'
# require 'rmagick'

namespace :assets do

Expand Down Expand Up @@ -47,46 +47,46 @@ def get_icons(type)
end

def get_twitter_images(data, type)
data.each do |vendor|
next if vendor['twitter'].blank?

begin
# FIXME: limit is 180
resp = RestClient.get("https://api.twitter.com/1.1/users/show.json?screen_name=#{vendor['twitter']}", authorization: "Bearer #{ENV['TWITTER_SECRET']}")

raise 'Bad response' unless resp.code == 200

profile = JSON.parse(resp.body)
# normal image URL
img_url = profile['profile_image_url_https']
vendor['image'] = img_url

# download largest image version
img_url.gsub!('normal', '400x400')
write_png_image("public/sources/#{type}/" << to_filename(vendor['vendor']), IO.open(img_url).read)

# process image
image = Magick::Image.read("public/sources/#{type}/" << to_filename(vendor['vendor']) << '.png').first

if type.eql? :vendor
file_path = 'public/img/vendor/' << to_filename(vendor['vendor'])
# small
small = image.scale(80, 80)
small.write(file_path + '.png')
# large
image.write(file_path + '_big.png')
else
# prepare for sprites
image.scale!(80, 80)
image.write("public/sources/#{type}/" << to_filename(vendor['vendor']) << '.png')
end
rescue StandardError => e
puts "Error retrieving image of #{vendor['vendor']}."
puts e.message
puts 'Consider that rate limiting is 15 minutes!'
end

end
# data.each do |vendor|
# next if vendor['twitter'].blank?
#
# begin
# # FIXME: limit is 180
# resp = RestClient.get("https://api.twitter.com/1.1/users/show.json?screen_name=#{vendor['twitter']}", authorization: "Bearer #{ENV['TWITTER_SECRET']}")
#
# raise 'Bad response' unless resp.code == 200
#
# profile = JSON.parse(resp.body)
# # normal image URL
# img_url = profile['profile_image_url_https']
# vendor['image'] = img_url
#
# # download largest image version
# img_url.gsub!('normal', '400x400')
# write_png_image("public/sources/#{type}/" << to_filename(vendor['vendor']), IO.open(img_url).read)
#
# # process image
# image = Magick::Image.read("public/sources/#{type}/" << to_filename(vendor['vendor']) << '.png').first
#
# if type.eql? :vendor
# file_path = 'public/img/vendor/' << to_filename(vendor['vendor'])
# # small
# small = image.scale(80, 80)
# small.write(file_path + '.png')
# # large
# image.write(file_path + '_big.png')
# else
# # prepare for sprites
# image.scale!(80, 80)
# image.write("public/sources/#{type}/" << to_filename(vendor['vendor']) << '.png')
# end
# rescue StandardError => e
# puts "Error retrieving image of #{vendor['vendor']}."
# puts e.message
# puts 'Consider that rate limiting is 15 minutes!'
# end
#
# end
end

end

0 comments on commit 4e53267

Please sign in to comment.