Home

Thursday, April 10, 2014

How to Reduce Image File Size Using PHP code?

<?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 = '1.jpg';
$destination_img = 'destination .jpg';

$d = compress($source_img, $destination_img, 70);
?>

No comments:

Post a Comment

rathoddhirendra.blogspot.com-Google pagerank and Worth