Visa ett inlägg
Oläst 2008-03-06, 10:15 #2
grinditwp grinditwp är inte uppkopplad
Flitig postare
 
Reg.datum: Mar 2008
Inlägg: 320
grinditwp grinditwp är inte uppkopplad
Flitig postare
 
Reg.datum: Mar 2008
Inlägg: 320
Här har ni funktionen jag använder mig av för att beskära bilderna. Fungerar helt smärtfritt på alla andra webbhotell jag kör på.

Kod:
function resizeImage($src, $dst, $dstx, $dsty){


$allowedExtensions = 'jpg jpeg gif png';

$name = explode(".", $src);
$currentExtensions = $name[count($name)-1];
$extensions = explode(" ", $allowedExtensions);

for($i=0; count($extensions)>$i; $i=$i+1){
if($extensions[$i]==$currentExtensions)
{ $extensionOK=1; 
$fileExtension=$extensions[$i]; 
break; }
}

if($extensionOK){

$size = getImageSize($src);
$width = $size[0];
$height = $size[1];

if($width >= $dstx AND $height >= $dsty){

$proportion_X = $width / $dstx;
$proportion_Y = $height / $dsty;

if($proportion_X > $proportion_Y ){
$proportion = $proportion_Y;
}else{
$proportion = $proportion_X;
}
$target['width'] = $dstx * $proportion;
$target['height'] = $dsty * $proportion;

$original['diagonal_center'] = 
round(sqrt(($width*$width)+($height*$height))/2);
$target['diagonal_center'] = 
round(sqrt(($target['width']*$target['width'])+
($target['height']*$target['height']))/2);

$crop = round($original['diagonal_center'] - $target['diagonal_center']);

if($proportion_X < $proportion_Y ){
$target['x'] = 0;
$target['y'] = round((($height/2)*$crop)/$target['diagonal_center']);
}else{
$target['x'] = round((($width/2)*$crop)/$target['diagonal_center']);
$target['y'] = 0;
}

if($fileExtension == "jpg" OR $fileExtension=='jpeg'){ 
$from = ImageCreateFromJpeg($src); 
}elseif ($fileExtension == "gif"){ 
$from = ImageCreateFromGIF($src); 
}elseif ($fileExtension == 'png'){
 $from = imageCreateFromPNG($src);
}

$new = ImageCreateTrueColor ($dstx,$dsty);

imagecopyresampled ($new, $from, 0, 0, $target['x'], 
$target['y'], $dstx, $dsty, $target['width'], $target['height']);

 if($fileExtension == "jpg" OR $fileExtension == 'jpeg'){ 
imagejpeg($new, $dst, 70); 
}elseif ($fileExtension == "gif"){ 
imagegif($new, $dst); 
}elseif ($fileExtension == 'png'){
imagepng($new, $dst);
}
}
}
}
grinditwp är inte uppkopplad   Svara med citatSvara med citat