Image Shot is quick, dirty, and simple internet image hosting script. It is **not a gallery** which means you won't upload an image and then be able to show it to others in your Image Shot gallery.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
3.5 KiB

  1. <?php
  2. $target_dir = "uploads";
  3. $url = "https://yourdomain.com";
  4. $target_file = $target_dir."/".basename($_FILES["fileToUpload"]["name"]);
  5. $img_sizes=array(400,600,800);
  6. $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
  7. // Only run if it's post data
  8. if(isset($_POST["submit"])) {
  9. // Authenticate-ish
  10. $images_salt=trim(file_get_contents("../../salt"));
  11. $post_salt=trim($_POST["post_salt"]);
  12. if ($images_salt != $post_salt ){
  13. die ("No");
  14. }
  15. // Make sure it is an image
  16. $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
  17. if($check == false) {
  18. echo "No";
  19. die();
  20. }
  21. // Check file size (10 MB)
  22. if ($_FILES["fileToUpload"]["size"] > 10000000) {
  23. echo "No.";
  24. die();
  25. }
  26. // Allow certain file formats
  27. if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg") {
  28. echo "No.";
  29. die();
  30. }
  31. // if everything is ok proceed
  32. $img=new Imagick($_FILES['fileToUpload']['tmp_name']);
  33. $head="<!DOCTYPE html>
  34. <html>
  35. <head>
  36. <title>Image Shot!</title>
  37. <meta name='viewport' content='width=device-width, initial-scale=1' />
  38. </head>
  39. <body>";
  40. $foot="</body>
  41. </html>";
  42. print $head;
  43. // Do the resizing routine
  44. $img_width=$img->getImageWidth();
  45. // Unique filename
  46. $salt=date('U');
  47. $target_filename=md5($new_image_name.$salt
  48. for ( $i=0; $i<count($img_sizes); $i++ ) {
  49. if ($img_width > $img_sizes[$i] ){
  50. $img->adaptiveResizeImage($img_sizes[$i],$img_sizes[$i],TRUE);
  51. }
  52. else { next; }
  53. // Tmp file name
  54. $new_image_name=$_FILES['fileToUpload']['tmp_name']."_$i";
  55. // Strip exif data
  56. $orientation = $img->getImageOrientation();
  57. $img->stripImage();
  58. $img=autorotate($img);
  59. // Save it
  60. $img->writeImage($new_image_name);
  61. if (copy($new_image_name, "$target_dir/$target_filename-".$img_sizes[$i].".$imageFileType")) {
  62. print "<img src='$url/$target_dir/$target_filename-".$img_sizes[$i].".$imageFileType' /><p />\n";
  63. print "<input type=text size=100 value='<img src=\"$url/$target_dir/$target_filename-".$img_sizes[$i].".$imageFileType\" />'/><br />\n";
  64. print "<input type=text size=100 value='![]($url/$target_dir/$target_filename-".$img_sizes[$i].".$imageFileType)'/><p />\n";
  65. } else {
  66. echo "Blerch. Something broke.<br />";
  67. }
  68. unlink ($new_image_name);
  69. imagedestroy($img);
  70. $img = new Imagick($_FILES['fileToUpload']['tmp_name']);
  71. }
  72. unlink ($_FILES['fileToUpload']['tmp_name']);
  73. print $foot;
  74. }
  75. // Orient it correctly
  76. function autorotate(Imagick $img)
  77. {
  78. switch ($img->getImageOrientation()) {
  79. case Imagick::ORIENTATION_TOPLEFT:
  80. break;
  81. case Imagick::ORIENTATION_TOPRIGHT:
  82. $img->flopImage();
  83. break;
  84. case Imagick::ORIENTATION_BOTTOMRIGHT:
  85. $img->rotateImage("#000", 180);
  86. break;
  87. case Imagick::ORIENTATION_BOTTOMLEFT:
  88. $img->flopImage();
  89. $img->rotateImage("#000", 180);
  90. break;
  91. case Imagick::ORIENTATION_LEFTTOP:
  92. $img->flopImage();
  93. $img->rotateImage("#000", -90);
  94. break;
  95. case Imagick::ORIENTATION_RIGHTTOP:
  96. $img->rotateImage("#000", 90);
  97. break;
  98. case Imagick::ORIENTATION_RIGHTBOTTOM:
  99. $img->flopImage();
  100. $img->rotateImage("#000", 90);
  101. break;
  102. case Imagick::ORIENTATION_LEFTBOTTOM:
  103. $img->rotateImage("#000", -90);
  104. break;
  105. default: // Invalid orientation
  106. break;
  107. }
  108. $img->setImageOrientation(Imagick::ORIENTATION_TOPLEFT);
  109. return $img;
  110. }
  111. ?>