- Kod: Zaznacz cały
function makeThumb($org_image, $dest_width = 0,$dest_height = 0){
if($org_image == null)
return false;
if(preg_match('/\.gif$/i', $org_image )){
$org_image = imagecreatefromgif($org_image);
}else if( preg_match('/\.png$/i', $org_image )){
$org_image = imagecreatefrompng($org_image);
}else if(preg_match('/\.bmp$/i', $org_image )){
$org_image = imagecreatefromwbmp($org_image);
}else{
$org_image = imagecreatefromjpeg($org_image);
}
$org_width = imagesx($org_image);
$org_height = imagesy($org_image);
if($dest_width > 0 && $dest_height > 0 ){
if($dest_width >= $org_width && $dest_height >= $org_height ){
return $org_image;
} else {
$dest_image = imagecreatetruecolor($dest_width, $dest_height);
}
}else if( ($dest_width > 0) && ($dest_height == 0) ){
$many = round(($org_width/$dest_width),1);
if($many > 1.0){
$dest_width = round($org_width/$many);
$dest_height = round($org_height/$many);
}else{
$dest_width = $org_width;
$dest_height = $org_height;
}
$dest_image = imagecreatetruecolor($dest_width, $dest_height);
}else if( ($dest_width == 0) && ($dest_height > 0) ){
$many = round(($org_height/$dest_height),1);
if($many > 1.0){
$dest_width = round($org_width/$many);
$dest_height = round($org_height/$many);
}else{
$dest_width = $org_width;
$dest_height = $org_height;
}
$dest_image = imagecreatetruecolor($dest_width, $dest_height);
}else{
$dest_width = 100;
$dest_height = 100;
$dest_image = imagecreatetruecolor($dest_width, $dest_height);
}
imagecopyresampled($dest_image, $org_image, 0, 0, 0, 0, $dest_width, $dest_height, $org_width ,$org_height );
return $dest_image;
}
duzo If-ow ,bo chcialem miec funkcje 1 uniwersalna.
A i $org_image to najczesciej $_FILES['picture']['name'][$pic] zdjecie dopiero wczytane