Poniżej pokazuje wam funkcje i skrypt
<?php function createthumbnail($filetype, $origfile, $thumbfile, $new_w, $new_h) { if ($filetype == 1) { $origimage = imagecreatefromgif($origfile); } elseif ($filetype == 2) { $origimage = imagecreatefromjpeg($origfile); } elseif ($filetype == 3) { $origimage = imagecreatefrompng($origfile); } $old_x = imagesx($origimage); $old_y = imagesy($origimage); if ($old_x > $new_w || $old_y > $new_h) { if ($old_x < $old_y) { $thumb_h = $new_h; } elseif ($old_x > $old_y) { $thumb_w = $new_w; } else { $thumb_w = $new_w; $thumb_h = $new_h; } } else { $thumb_w = $old_x; $thumb_h = $old_y; } if ("gd2" == "gd1") { $thumbimage = imagecreate($thumb_w,$thumb_h); $result = imagecopyresized($thumbimage, $origimage, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y); } else { $thumbimage = imagecreatetruecolor($thumb_w,$thumb_h); $result = imagecopyresampled($thumbimage, $origimage, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y); } if ($filetype == 1) { imagegif($thumbimage, $thumbfile); } elseif ($filetype == 2) { imagejpeg($thumbimage, $thumbfile); } elseif ($filetype == 3) { imagepng($thumbimage, $thumbfile); } } function image_exists($dir, $image) { $i = 1; $image = $image_name."_".$i.$image_ext; $i++; } return $image; } ?>
<?php require_once("manicore.php"); require_once("header.php"); require_once("include/photo_functions_include.php"); $photo_title = stripinput($_POST['photo_title']); $photo_source = stripinput($_POST['photo_source']); $photo_file = ""; $photo_thumb1 = ""; $photo_thumb2 = ""; $photo_pic = $_FILES['myfile']; $photo_dest = "http://localhost/test/uploads/"; $error = "error1"; } elseif ($photo_pic['size'] > 4150000){ $error = "error2"; $error = "error3"; } else { $photo_file = image_exists($photo_dest, $photo_name.$photo_ext); chmod($photo_dest.$photo_file, 0644); if ($imagefile[0] > 2000 || $imagefile[1] > 2000) { $error = "error4"; } else { $photo_thumb1 = image_exists($photo_dest, $photo_name."_t1".$photo_ext); createthumbnail($imagefile[2], $photo_dest.$photo_file, $photo_dest.$photo_thumb1, 100, 100); if ($imagefile[0] > 500 || $imagefile[1] > 1100) { $photo_thumb2 = image_exists($photo_dest, $photo_name."_t2".$photo_ext); createthumbnail($imagefile[2], $photo_dest.$photo_file, $photo_dest.$photo_thumb2, 500, 1100); } } } } } ?>