
The default is dpr(1), which means image is for regular displays, and resize() does the obvious thing you'd expect. dpr($x) - pixel doubling for responsive images (HTML srcset) See options reference for more resizing options. If you don't call resize(), then the original image size will be preserved. Resize($width, $height, 'crop') - resizes and crops image exactly to these dimensions. 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.
#IMAGEOPTIM FULL#
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. type d -exec sh -c ".This library allows you to resize and optimize images using ImageOptim API.


You can try this oneliner using find and perl: sudo find. Ideally I just want to see one number - how much size have I saved.īecause this is my first bash script (I struggled for an hour with that loop :-( ), my skills currently are not sufficient to solve my problem. When I try to suppress it with -t -q or -tq or -q -t (I tried them all because I am not sure it it matters) it showed no information at all. But I do not want to get all information about each individual image. It outputs the line Average compression (6 files): 7.26% (8k) because I asked for a summary with the -t flag. When I run the script it outputs the following: mydir/dir_1/img_1.jpg axb 24bit N JFIF 2234 -> 1861 bytes (16.70%), optimized. My script looks as below and from functional point of view it does exactly what I want: for dir in mydir/*/ It took me quite some time to learn rudimentary bash scripting to able to optimize all images in all my first level directories. I am using imageOptim to optimize images on my server.
