Resize($width, $height) - same as above, but image will also have height same or smaller. If the image is smaller than this, it won't be enlarged. Resize($width) - sets maximum width for the image, so it'll be resized to this width. resize($width, $height = optional, $fit = optional) - desired dimensions If source images you provide are already saved at low quality, ImageOptim will not be able to make them look better. JPEG saved at 99%), so that ImageOptim can adjust quality itself. Ideally you should supply source image at very high quality (e.g. Please pass full absolute URL to images on your website. published on a website) it's faster to use the URL method instead: imageFromURL($url) - remote source imageĬreates a new request that will read the image from the given public URL, and then resize and optimize it. localhost, files in /tmp).įor images that have a public URLs (e.g. The upload method is necessary for optimizing files that are not on the web (e.g. imageFromPath($filePath) - local source imageĬreates a new request that will upload the image to the API, and then resize and optimize it. Methods API($username) constructor new ImageOptim\API("your api username goes here") Ĭreates new instance of the API. There's a longer example at the end of the readme. > getBytes() // perform these operations and return the image data as binary stringįile_put_contents(" images/photo_optimized.jpg", $imageData) > dpr( 2) // optional: double number of pixels for high-resolution "Retina" displays > resize( 160, 100, 'crop') // optional: resize to a thumbnail If you don't use Composer, then require or autoload files from the src directory. The easiest is to use PHP Composer: composer require imageoptim/imageoptim ImageOptim offers advanced compression, high-DPI/responsive image mode, and color profile support that are much better than PHP's built-in image resizing functions. This library allows you to resize and optimize images using ImageOptim API.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |