So, I have the following image compression function but I am not sure if it is doing what it is supposed to do.
It is in php file:
function compress_image($src, $dest , $quality)
{
$upload_dir = wp_upload_dir();
$info = getimagesize($src);
if ($info['mime'] == 'image/jpeg')
{
$image = imagecreatefromjpeg($src);
}
elseif ($info['mime'] == 'image/gif')
{
$image = imagecreatefromgif($src);
}
elseif ($info['mime'] == 'image/png')
{
$image = imagecreatefrompng($src);
}
else
{
die('Unknown image file format');
}
if (!file_exists($upload_dir['path'] . '/compress')) {
mkdir($upload_dir['path'] . '/compress', 0777, true);
}
imagejpeg($image, $dest, $quality);
}
Is it correctly written?
The result "compressed" image seems to be small (ex, 2MB to 500kb), but I am not sure if the compression is done on the client side (on their phone or computer while being uploaded but before uploaded to the server), or on the server side.
My goal is to compress the image before being uploaded so it is quicker in uploading process.
What do you think?