README.md in imgkit-1.2.1 vs README.md in imgkit-1.3.0

- old
+ new

@@ -23,47 +23,82 @@ kit = IMGKit.new(html, :quality => 50) kit.stylesheets << '/path/to/css/file' # Get the image BLOB img = kit.to_img - - # Save the JPG to a file + + # New in 1.3! + img = kit.to_img(:jpg) #default + img = kit.to_img(:jpeg) + img = kit.to_img(:png) + img = kit.to_img(:tif) + img = kit.to_img(:tiff) + + # Save the image to a file file = kit.to_file('/path/to/save/file.jpg') + file = kit.to_file('/path/to/save/file.png') # IMGKit.new can optionally accept a URL or a File. # Stylesheets can not be added when source is provided as a URL of File. kit = IMGKit.new('http://google.com') kit = IMGKit.new(File.new('/path/to/html')) # Add any kind of option through meta tags - IMGKit.new('<html><head><meta name="imgkit-quality" content="75") + IMGKit.new('<html><head><meta name="imgkit-quality" content="75"... + + # Format shortcuts - New in 1.3! + IMGKit.new("hello").to_jpg + IMGKit.new("hello").to_jpeg + IMGKit.new("hello").to_png + IMGKit.new("hello").to_tif + IMGKit.new("hello").to_tiff ## Configuration -If you're on Windows or you installed wkhtmltoimage by hand to a location other than /usr/local/bin you will need to tell PDFKit where the binary is. You can configure PDFKit like so: +If you're on Windows or you installed wkhtmltoimage by hand to a location other than /usr/local/bin you will need to tell IMGKit where the binary is. You can configure IMGKit like so: # config/initializers/imgkit.rb IMGKit.configure do |config| config.wkhtmltoimage = '/path/to/wkhtmltoimage' config.default_options = { :quality => 60 } + config.default_format = :png end - ## Rails ### Mime Types register a .jpg mime type in: #config/initializers/mime_type.rb Mime::Type.register "image/jpeg", :jpg +register a .png mime type in: + + #config/initializers/mime_type.rb + Mime::Type.register "image/png", :png + ### Controller Actions -You can then send JPGs with +You can respond in a controller with: + @kit = IMGKit.new(render_as_string) + format.jpg do - send_data(@kit.to_img, :type => "image/jpeg", :disposition => 'inline') + send_data(@kit.to_jpg, :type => "image/jpeg", :disposition => 'inline') + end + + - or - + + format.png do + send_data(@kit.to_png, :type => "image/png", :disposition => 'inline') + end + + - or - + + respond_to do |format| + send_data(@kit.to_img(format.to_sym), + :type => "image/png", :disposition => 'inline') end This allows you to take advantage of rails page caching so you only generate the image when you need to.