Compress image size without lose quality using php

Compress image size without lose quality


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_image = ‘original_folder/original_image.jpg’;
$compress_image = ‘compress_folder/compress_image.jpg’;

$compressimage = $this->compress($source_image, $compress_image, 90);

First parameter for original image where we have uploaded original image
Second parameter for actual compress image where we will need compress image.
Third parameter for quality whatever you set. 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s