$max_file_size) throw new Exception("File over allowed size of {$max_filesize_msg}"); // Get the extension of the file $file_ext = pathinfo($file_name, PATHINFO_EXTENSION); $file_id = rand_str(6); // Convert webp files into jpg image if ($type == 'image/webp') { $new_file_name = "{$file_id}.jpg"; $new_thumb_name = "{$file_id}_thumb.jpg"; // Convert webp to jpeg with 80% quality and save to save path $im = imagecreatefromwebp($tmp_name); imagejpeg($im, $image_path . $new_file_name, 80); imagedestroy($im); } // Resize image if it's JPEG and more then 1200px in any side elseif ($type == 'image/jpeg' && ($image_info[0] > $max_image_size || $image_info[1] > $max_image_size)) { $new_file_name = "{$file_id}.jpg"; $new_thumb_name = "{$file_id}_thumb.jpg"; // Resize image to a smaller size $source = $tmp_name; $dest = $image_path . $new_file_name; resizeAndSaveImage($source, $dest, $max_image_size); } // Move the uploaded file to save path else { $new_file_name = "{$file_id}.{$file_ext}"; $new_thumb_name = "{$file_id}_thumb.{$file_ext}"; // Move the uploaded file to save path (for all other formats) move_uploaded_file($tmp_name, $image_path . $new_file_name); } // Generate thumbnails $source = $image_path . $new_file_name; $dest = $thumb_path . $new_thumb_name; resizeAndSaveImage($source, $dest, 150); // Generate the file url and reply $url = $protocol . $domain . $image_url . $new_file_name; $out = array("status" => "OK", "url" => $url); echo json_encode($out); } // Catch and print the exception catch (Exception $e) { $out = array("status" => "FAIL", "msg" => $e->getMessage()); echo json_encode($out); } } else { $v = "?v=" . rand(1111, 9999); ?> Mini Image Host
Mini Image Host
Mini Image Host
Select mirror:

Browse Image to Upload

Max file size:
= 0; $i--) { $value = pow(1024, $i); if ($raw_size > $value) { $size_hr = round(($raw_size / $value), 2); return $return_array ? array($size_hr, $size_arr[$i]) : "{$size_hr} {$size_arr[$i]}"; } } } // Resize and save image function resizeAndSaveImage($source, $dest, $maxSize = 200) { // get source image size $img_details = getimagesize($source); $w = $img_details[0]; $h = $img_details[1]; $img_type = $img_details[2]; // specifying the required image size if ($w > $h) { $new_width = $maxSize; $new_height = ceil($maxSize * $h / $w); } else { $new_height = $maxSize; $new_width = ceil($maxSize * $w / $h); } if ($img_type == IMAGETYPE_GIF) { $imgt = "ImageGIF"; $imgcreatefrom = "ImageCreateFromGIF"; } elseif ($img_type == IMAGETYPE_JPEG) { $imgt = "ImageJPEG"; $imgcreatefrom = "ImageCreateFromJPEG"; } elseif ($img_type == IMAGETYPE_PNG) { $imgt = "ImagePNG"; $imgcreatefrom = "ImageCreateFromPNG"; } if ($imgt) { $old_image = $imgcreatefrom($source); $new_image = imagecreatetruecolor($new_width, $new_height); imagecopyresized($new_image, $old_image, 0, 0, 0, 0, $new_width, $new_height, $w, $h); $save = $imgt($new_image, $dest); } }