Advertisement
fahmihilmansyah

image convert

Jul 16th, 2013
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1.  
  2. function compress_image($source_url, $destination_url, $quality) {
  3. $info = getimagesize($source_url);
  4.  
  5. if ($info['mime'] == 'image/jpeg') $image = imagecreatefromjpeg($source_url);
  6. elseif ($info['mime'] == 'image/gif') $image = imagecreatefromgif($source_url);
  7. elseif ($info['mime'] == 'image/png') $image = imagecreatefrompng($source_url);
  8.  
  9. //save it
  10. imagejpeg($image, $destination_url, $quality);
  11.  
  12. //return destination file url
  13. return $destination_url;
  14. }
  15.  
  16. $source_photo = 'uploads/im.png';
  17. $dest_photo = 'uploads/im.png';
  18.  
  19. $d = compress_image($source_photo, $dest_photo, 50); //50 merupakan berapa persen mau di kecilin pixelnya,semakin kecil persennya semakin besar pixel yg di tampilkan
  20.  
  21. echo '
  22. <div style="float:left;margin-right:10px">
  23. <img src="'.$source_photo.'" alt="" />
  24. <br />'.filesize($source_photo).' Bytes
  25. </div>
  26.  
  27. <div style="float:left;">
  28. <img src="'.$dest_photo.'" alt="" />
  29. <br />'.filesize($dest_photo).' Bytes
  30. </div>
  31. ';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement