discourse/lib/image_optimizer.rb

49 lines
1.5 KiB
Ruby
Raw Normal View History

2013-02-22 07:47:26 -05:00
# This class is used to download and optimize images.
#
2013-02-25 11:42:20 -05:00
# I have not had a chance to implement me, and will not for about 3 weeks.
# If you are looking for a small project this simple API would be a good stint.
2013-02-22 07:47:26 -05:00
#
2013-02-25 11:42:20 -05:00
# Implement the following methods. With tests, the tests are a HUGE PITA cause
# network, disk and external dependencies are involved.
2013-02-21 18:56:59 -05:00
class ImageOptimizer
2013-02-22 07:47:26 -05:00
attr_accessor :url, :root_dir
2013-02-25 11:42:20 -05:00
# url is a url of an image ex:
2013-02-22 07:47:26 -05:00
# 'http://site.com/image.png'
# '/uploads/site/image.png'
#
2013-02-25 11:42:20 -05:00
# root_dir is the path where we
2013-02-22 07:47:26 -05:00
# store optimized images
def initialize(opts = {})
@url = opts[:url]
@root_dir = opts[:root_dir]
2013-02-21 18:56:59 -05:00
end
2013-02-25 11:42:20 -05:00
# attempt to refresh the original image, if refreshed
2013-02-22 07:47:26 -05:00
# remove old downsized copies
2013-02-25 11:42:20 -05:00
def refresh_local!
end
2013-02-22 07:47:26 -05:00
# clear all local copies of the images
def clear_local!
2013-02-21 18:56:59 -05:00
end
2013-02-25 11:42:20 -05:00
2013-02-22 07:47:26 -05:00
# yeild a list of relative paths to local images cached
def each_local
end
2013-02-25 11:42:20 -05:00
# return the path of an optimized image,
# if already cached return cached, else download and cache
# at the original size.
2013-02-22 07:47:26 -05:00
# if size is specified return a resized image
2013-02-25 11:42:20 -05:00
# if height or width are nil maintain aspect ratio
#
# Optimised image is the "most efficient" storage for an image
2013-02-22 07:47:26 -05:00
# at the basic level it runs through image_optim https://github.com/toy/image_optim
2013-02-25 11:42:20 -05:00
# it also has a failsafe that converts jpg to png or the opposite. if jpg size is 1.5*
# as efficient as png it flips formats.
2013-02-22 07:47:26 -05:00
def optimized_image_path(width=nil, height=nil)
2013-02-21 18:56:59 -05:00
end
end