I am trying to develop an image-based web site. I am really confused about the best image type for faster page loading speeds and best compression practices. Please advise me on the best way to compress image sizes.
Compress the image: If it still exceeds the maximum size or weight of 2 mb you can go one step further by compressing it. To compress an image, many tools offer a sliding scale. Moving to the left of the scale will reduce the image's file size, but also its quality.
The most common side effect of scaling an image larger than its original dimensions is that the image may appear to be very fuzzy or pixelated. Scaling images smaller than the original dimensions does not affect quality as much, but can have other side effects.
The primary way to reduce the file size of an image is by increasing the amount of compression. In most image editing applications this is done by the selections you make in the “Save As” or “Export As” dialog box when saving a PNG, JPG, or GIF.
Many people think that lowering the resolution of an image also lowers the file size of the image, allowing it to download faster over the web. But while it's true that smaller files sizes download faster, the resolution of your image has nothing to do with its file size.
If you are looking to reduce the size using coding itself, you can follow this code in php.
<?php function compress($source, $destination, $quality) { $info = getimagesize($source); if ($info['mime'] == 'image/jpeg') $image = imagecreatefromjpeg($source); elseif ($info['mime'] == 'image/gif') $image = imagecreatefromgif($source); elseif ($info['mime'] == 'image/png') $image = imagecreatefrompng($source); imagejpeg($image, $destination, $quality); return $destination; } $source_img = 'source.jpg'; $destination_img = 'destination .jpg'; $d = compress($source_img, $destination_img, 90); ?>
$d = compress($source_img, $destination_img, 90);
This is just a php function that passes the source image ( i.e., $source_img
), destination image ( $destination_img
) and quality for the image that will take to compress ( i.e., 90 ).
$info = getimagesize($source);
The getimagesize()
function is used to find the size of any given image file and return the dimensions along with the file type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With