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.
 
 

126 lines
3.5 KiB

<?php
$target_dir = "uploads";
$url = "https://yourdomain.com";
$target_file = $target_dir."/".basename($_FILES["fileToUpload"]["name"]);
$img_sizes=array(400,600,800);
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Only run if it's post data
if(isset($_POST["submit"])) {
// Authenticate-ish
$images_salt=trim(file_get_contents("../../salt"));
$post_salt=trim($_POST["post_salt"]);
if ($images_salt != $post_salt ){
die ("No");
}
// Make sure it is an image
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check == false) {
echo "No";
die();
}
// Check file size (10 MB)
if ($_FILES["fileToUpload"]["size"] > 10000000) {
echo "No.";
die();
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg") {
echo "No.";
die();
}
// if everything is ok proceed
$img=new Imagick($_FILES['fileToUpload']['tmp_name']);
$head="<!DOCTYPE html>
<html>
<head>
<title>Image Shot!</title>
<meta name='viewport' content='width=device-width, initial-scale=1' />
</head>
<body>";
$foot="</body>
</html>";
print $head;
// Do the resizing routine
$img_width=$img->getImageWidth();
// Unique filename
$salt=date('U');
$target_filename=md5($new_image_name.$salt
for ( $i=0; $i<count($img_sizes); $i++ ) {
if ($img_width > $img_sizes[$i] ){
$img->adaptiveResizeImage($img_sizes[$i],$img_sizes[$i],TRUE);
}
else { next; }
// Tmp file name
$new_image_name=$_FILES['fileToUpload']['tmp_name']."_$i";
// Strip exif data
$orientation = $img->getImageOrientation();
$img->stripImage();
$img=autorotate($img);
// Save it
$img->writeImage($new_image_name);
if (copy($new_image_name, "$target_dir/$target_filename-".$img_sizes[$i].".$imageFileType")) {
print "<img src='$url/$target_dir/$target_filename-".$img_sizes[$i].".$imageFileType' /><p />\n";
print "<input type=text size=100 value='<img src=\"$url/$target_dir/$target_filename-".$img_sizes[$i].".$imageFileType\" />'/><br />\n";
print "<input type=text size=100 value='![]($url/$target_dir/$target_filename-".$img_sizes[$i].".$imageFileType)'/><p />\n";
} else {
echo "Blerch. Something broke.<br />";
}
unlink ($new_image_name);
imagedestroy($img);
$img = new Imagick($_FILES['fileToUpload']['tmp_name']);
}
unlink ($_FILES['fileToUpload']['tmp_name']);
print $foot;
}
// Orient it correctly
function autorotate(Imagick $img)
{
switch ($img->getImageOrientation()) {
case Imagick::ORIENTATION_TOPLEFT:
break;
case Imagick::ORIENTATION_TOPRIGHT:
$img->flopImage();
break;
case Imagick::ORIENTATION_BOTTOMRIGHT:
$img->rotateImage("#000", 180);
break;
case Imagick::ORIENTATION_BOTTOMLEFT:
$img->flopImage();
$img->rotateImage("#000", 180);
break;
case Imagick::ORIENTATION_LEFTTOP:
$img->flopImage();
$img->rotateImage("#000", -90);
break;
case Imagick::ORIENTATION_RIGHTTOP:
$img->rotateImage("#000", 90);
break;
case Imagick::ORIENTATION_RIGHTBOTTOM:
$img->flopImage();
$img->rotateImage("#000", 90);
break;
case Imagick::ORIENTATION_LEFTBOTTOM:
$img->rotateImage("#000", -90);
break;
default: // Invalid orientation
break;
}
$img->setImageOrientation(Imagick::ORIENTATION_TOPLEFT);
return $img;
}
?>