See options reference for explanation how DPR works. This is better than resize($width*2), because it also adjusts sharpness and image quality to be optimal for high-DPI displays. If you set dpr(2) then pixel width and height of the image will be doubled to match density of "2x" displays. 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. 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. To do this, I advise you to use these free filters for color correction.This library allows you to resize and optimize images using ImageOptim API. In addition, websites with a good rating on search engines get more customers wishing to purchase their services and products.īefore you compress PNG or other images, you should edit them in Photoshop or Lightroom. As a result, you will get more potential customers and increased sales. Thanks to the fast loading of your website, more users will visit it and spend more time there. Therefore, using the best image optimizer, you get a huge advantage. As I mentioned earlier, images make up a significant part of the website's weight. The last study showed that if the site is loading for more than three seconds, then about 53% of people do not wait for its completion and leave the page. These factors are particularly important for mobile users. High-performance, fast-load websites attract more people. Since Google prefers fast page loading, websites with high dimensioned images are inferior to their well-optimized competitors. It Improves Your Site SEO ScoreĪ high SEO ranking is another reason for using image resizer. Use photo compression software free or paid to reduce the size of your content without losing in quality and speed up website loading. The smaller the size of the pictures, the faster the site works. In addition to images, it needs to load other content like JS and CCS. Using HD dimension images affects the speed of your site. Therefore, by compressing the pictures, you optimize the performance of your website significantly. This is the second indicator after video content. If we analyze the HTTP Archive data, about 21% of the web page is occupied by images. Using the best image optimizer provides you with a number of advantages that improve your website’s performance. I believe that if shrinking to 70% is not available to the ordinary user without buying a premium plan or changing the settings, such a photo compression tool should be at the bottom of the list. However, the fact that they demonstrate good efficiency plays in their favor. You see that the same image optimization tools were the leaders in both tests. However, its three competitors also showed decent results. Talking about the PNG optimizer, the results turned out to be closer.
0 Comments
Leave a Reply. |