image_compressed.php 993 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. $url = "";
  3. $filetype = "";
  4. $raw_image = NULL;
  5. //get the image url
  6. if (isset( $_GET['i'] ) ) {
  7. $url = $_GET[ 'i' ];
  8. } else {
  9. exit();
  10. }
  11. //an image will start with http, anything else is sus
  12. if (substr( $url, 0, 4 ) != "http") {
  13. exit();
  14. }
  15. //we can only do jpg and png here
  16. if (strpos($url, ".jpg") || strpos($url, ".jpeg") === true) {
  17. $filetype = "jpg";
  18. $raw_image = imagecreatefromjpeg($url);
  19. } elseif (strpos($url, ".png") === true) {
  20. $filetype = "png";
  21. $raw_image = imagecreatefrompng($url);
  22. } else {
  23. exit();
  24. }
  25. $dest_imagex = 300;
  26. $dest_imagey = 200;
  27. $dest_image = imagecreatetruecolor($dest_imagex, $dest_imagey);
  28. imagecopyresized($dest_image, $raw_image, 0, 0, 0, 0, $dest_imagex, $dest_imagey, imagesx($raw_image), imagesy($raw_image));
  29. header('Content-type: image/' . $filetype);
  30. if ($filetype = "jpg") {
  31. imagejpeg($dest_image,NULL,80); //80% quality
  32. } elseif ($filetype = "png") {
  33. imagepng($dest_image,NULL,8); //80% compression
  34. }
  35. ?>