Code: Alles auswählen
...
...
private static function scaleImg($fn,$maxDim) {
list($width, $height, $type, $attr) = getimagesize($_FILES['imagefile']['tmp_name']);
$size = getimagesize($fn);
$ratio = $size[0] / $size[1]; // width/height
if ($ratio = 1) { // width/height = 1
$width = $maxDim; // leave width
$height = $maxDim; // leave height
}
if ($ratio > 1) { // width/heigth > 1
$width = $maxDim; // leave width
$height = $maxDim / $ratio; // calculate new height
}
if ($ratio < 1) { // width/height < 1
$width = $maxDim * $ratio; // calculate new width
$height = $maxDim; // leave height
}
$src = imagecreatefromstring(file_get_contents($fn));
$dst = imagecreatetruecolor($width, $height);
imagealphablending($dst, false);
imagesavealpha($dst, true);
$transparent = imagecolorallocatealpha($dst, 255, 255, 255, 127);
imagefilledrectangle($dst, 0, 0, $width, $height, $transparent);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
imagedestroy($src);
ob_start();
imagepng($dst); // adjust format as needed
$imagedata = ob_get_contents();
ob_end_clean();
imagedestroy($dst);
return $imagedata;
}
...
...