function cutImage($file, $save_path, $save_name, $width, $height) { $ext = ".jpg"; $infos = getimagesize($file . $ext); if ($infos[0] < 200) { return false; } if ($infos[0] > $infos[1]) { thumbImage($file . $ext, $save_path . $save_name . $ext, 500, 51); $infos_small = getimagesize($save_path . $save_name . $ext); $x = $infos_small[0] > 50 ? ($infos_small[0] - 50) / 2 : 0; $point = array($x, 0); // Koordinaten, ab wo kopiert werden soll (erst X, dann Y). } else { thumbImage($file . $ext, $save_path . $save_name . $ext, 51, 500); $infos_small = getimagesize($save_path . $save_name . $ext); $y = $infos_small[1] > 50 ? ($infos_small[1] - 50) / 2 : 0; $point = array(0, $y); // Koordinaten, ab wo kopiert werden soll (erst X, dann Y). } $size = array(50, 50); // Breite und Höhe des Auschnitts $image = imagecreatefromjpeg($save_path . $save_name . $ext); // Original einlesen $new = imagecreatetruecolor($size[0], $size[1]); // Neues Bild leer erstellen imagecopyresampled($new, $image, 0, 0, $point[0], $point[1], $size[0], $size[1], $size[0], $size[1]); // Ausschnitt rüberkopieren imagejpeg($new, $save_path . "small/" . $save_name . $ext, 100); // Neues Bild speichern unlink($save_path . $save_name . $ext); $width = 200; $height = $width * 10; thumbImage($file . $ext, $save_path . $save_name . $ext, $width, $height); return true; }
<?php function getExtension($filename) { return pathinfo($filename, PATHINFO_EXTENSION); } function uuid() { return md5(uniqid(microtime() . mt_rand())); } header('content-type:text/html;charset=utf-8'); require_once 'inc/image.inc.php'; foreach ($_FILES['image']['error'] as $key => $error) { if ($error === UPLOAD_ERR_OK) { $imagename = $_FILES['image']['name'][$key]; $dst = 'images/' . uuid() . '.' . getExtension($imagename); thumbImage($_FILES['image']['tmp_name'][$key], 0.5, $dst); } }