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…

How to sort array on given key in php?

Sometime we require array in specific order that time we need to sort array in specific order in ascending or descending orderĀ as par requirement view. Using php array key we can sort array in ascending or descending order Here first argument is pass array data, second is the array key and third one is optional,…

Convert stdClass object to array in pHp

Object to array convert in php For e.g Array ( [0] => stdClass Object ( [user_id] => 10 ) [1] => stdClass Object ( [user_id] => 20 ) ) Convert into array Array ( [0] => 10 [1] => 20 ) $array = json_decode(json_encode($object),true);