discourse/lib/image_optimizer.rb

49 lines
1.5 KiB
Ruby
Raw Normal View History

2013-02-22 20:47:26 +08:00
# This class is used to download and optimize images.
#
2013-02-26 00:42:20 +08: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 20:47:26 +08:00
#
2013-02-26 00:42:20 +08:00
# Implement the following methods. With tests, the tests are a HUGE PITA cause
# network, disk and external dependencies are involved.
2013-02-22 07:56:59 +08:00
class ImageOptimizer
2013-02-22 20:47:26 +08:00
attr_accessor :url, :root_dir
2013-02-26 00:42:20 +08:00
# url is a url of an image ex:
2013-02-22 20:47:26 +08:00
# 'http://site.com/image.png'
# '/uploads/site/image.png'
#
2013-02-26 00:42:20 +08:00
# root_dir is the path where we
2013-02-22 20:47:26 +08:00
# store optimized images
def initialize(opts = {})
@url = opts[:url]
@root_dir = opts[:root_dir]
2013-02-22 07:56:59 +08:00
end
2013-02-26 00:42:20 +08:00
# attempt to refresh the original image, if refreshed
2013-02-22 20:47:26 +08:00
# remove old downsized copies
2013-02-26 00:42:20 +08:00
def refresh_local!
end
2013-02-22 20:47:26 +08:00
# clear all local copies of the images
def clear_local!
2013-02-22 07:56:59 +08:00
end
2013-02-26 00:42:20 +08:00
2013-03-06 15:52:24 +08:00
# yield a list of relative paths to local images cached
2013-02-22 20:47:26 +08:00
def each_local
end
2013-02-26 00:42:20 +08:00
# return the path of an optimized image,
# if already cached return cached, else download and cache
# at the original size.
2013-02-22 20:47:26 +08:00
# if size is specified return a resized image
2013-02-26 00:42:20 +08:00
# if height or width are nil maintain aspect ratio
#
# Optimised image is the "most efficient" storage for an image
2013-02-22 20:47:26 +08:00
# at the basic level it runs through image_optim https://github.com/toy/image_optim
2013-02-26 00:42:20 +08: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 20:47:26 +08:00
def optimized_image_path(width=nil, height=nil)
2013-02-22 07:56:59 +08:00
end
end