

In case you want to include formats that do not support transparency (JPEG), one can specify a background color that replaces the transparency using the transform object. Images with a transparent background will only be converted to formats that support transparency. source = om_file( "panda-sticker.jpg")Ĭonverted = nvert( type: )Ĭonverted.to_file( "panda-sticker." + extension) Image converting will count as one additional compression. When you provide more than one image type in your convert request, the smallest version will be returned to you. Tinify currently supports converting between WebP, JPEG, and PNG. You can use the API to convert your images to your desired image type. Scaling up is prevented in order to protect the If the target dimensions are larger than the original dimensions, the image If an image is detected with aįree standing object it will add more background space where The followingĪ more advanced implementation of cover that also detects cut out The method describes the way your image will be resized. To resize an image, call the resize method on an image source: source = om_file( "large.jpg") This will count as 3 compressions in total. For example, if you uploadĪ single image and retrieve the optimized version plus 2 resized versions Resizing counts as one additional compression. That focus on the most visually important areas of your image. You can also take advantage of intelligent cropping to create thumbnails Optimally compressed with a nice and crisp appearance. You will only have to upload your image once. The API handle resizing you avoid having to write such code yourself and Use the API to create resized versions of your uploaded images. You can provide a URL to your image instead of having to upload it. Result_data = om_buffer(source_data).to_buffer Source_data = File.read( "unoptimized.jpg") You can also upload an image from a buffer (a string with binary) and get You can choose a local file as the source and write it to another file. Compression will start as soon as you upload a Will automatically detect the type of image and optimise with the TinyPNG or You can upload any WebP, JPEG or PNG image to the Tinify API to compress it. Set the URL of your proxy server, which can optionally include credentials. You can instruct the API client to make all requests over an HTTP proxy. Always keep your API key secret! require "tinify"Īll requests will be made over an encrypted Get an API key by registering with your name andĮmail address. To use the API you must provide your API key. Installationīy adding this line to your application’s Gemfile: gem "tinify" Languages make it very easy to interact with the Tinify API.


The Tinify API allows you to compress and optimize WebP, JPEG and PNG images.
