Witam
Używam poniżeszj funkcji do tworzenia miniaturek ale chyba jest z nią cos nie tak bo obcina zdjęcia.
Na przykład kawałek zdjęcia na górze i na dole.
<?php
function imgType($name) {
if($roz == '.jpg' || $roz == 'jpeg' || $roz == '.jpe') {
return "IMAGETYPE_JPEG";
} elseif($roz == '.gif') {
return "IMAGETYPE_GIF";
} elseif($roz == '.png') {
return "IMAGETYPE_PNG";
} else {
return "IMAGETYPE_JPEG";
}
}
function resizeImage($source, $max_x, $max_y, $save_image, $jpeg_quality = 90) {
if (imgType($source) == "IMAGETYPE_JPEG"){
$img_src = imagecreatefromjpeg($source);
} else if (imgType($source) == "IMAGETYPE_GIF"){
$img_src = imagecreatefromgif($source);
} else if (imgType($source) == "IMAGETYPE_PNG"){
$img_src = imagecreatefrompng($source);
}
$image_x = imagesx($img_src);
$image_y = imagesy($img_src);
if($image_x > $image_y) {
$ratio_x = ($image_x > $max_x) ? $max_x/$image_x : 1;
$ratio_y = $ratio_x;
$move = 'y';
} else {
$ratio_y = ($image_y > $max_y) ? $max_y/$image_y : 1;
$ratio_x = $ratio_y;
$move = 'x';
}
$new_x = $image_x*$ratio_x;
$new_y = $image_y*$ratio_y;
$move_x = ($move == "x") ? ($max_x-$new_x)/2 : 0;
$move_y = ($move == "y") ? ($max_y-$new_y)/2 : 0;
$new_img = imagecreatetruecolor($max_x, $max_y);
$background = imagecolorallocate($new_img, 255, 255, 255);
imagefill($new_img, 0, 0, $background);
imagecopyresampled($new_img, $img_src, $move_x, $move_y, 0, 0, $new_x, $new_y, $image_x, $image_y);
if(imgType($save_image) == "IMAGETYPE_JPEG") {
imagejpeg($new_img, $save_image, 100);
} elseif(imgType($save_image) == "IMAGETYPE_GIF") {
imagegif($new_img, $save_image);
} elseif(imgType($save_image) == "IMAGETYPE_PNG") {
imagepng($new_img, $save_image);
}
}
?>
Widzi ktoś może błąd?
Pozdrawiam