Hey,
Op zich heb ik n aardig script gevonden om afbeeldingen online te resizen.
Alleen heb ik 1 probleem:
Als ik n afbeelding verklein met dit script word de output groter dan de originele file.
originele filesize: 83 Kb
verkleint naar 150 x 150 pixels: 35 Kb
verkleint naar 400 x 400 pixels: 210 Kb
Ik weet dat er n manier is om 'output' JPG files een waarde in procenten mee te geven zodat die (zonder kwaliteitsverlies) kleiner word, heb t geprobeerd om dit erin te bouwen maar kom er niet uit.
Heeft iemand van jullie enig idee??
SCRIPT:
<?php
$source="waterlelies.jpg";
$output="waterlelies_thumb.jpg";
//Dimensions
$outWidth=400;
$outHeight=400;
//Do it
$imgSrc=imagecreatefromjpeg($source);
$srcWidth=imagesx($imgSrc);
$srcHeight=imagesy($imgSrc);
//Make thumbnails
$imgOut=imagecreatetruecolor($outWidth,$outHeight);
imagerectangle($imgOut,0,0,$outWidth,$outHeight,
imagecolorallocate($imgOut,0,0,0));
//Copy them proportionatly
$dx=0; $dy=0; $dw=$outWidth; $dh=$outHeight;
if ($outWidth*$srcHeight!=$outHeight*$srcWidth) { //Non-proportional, cut-off
//Which dimensions is larger
if ($srcWidth>$srcHeight) { //Empty space on top and bottom
$dw=$outWidth;
$dh=($dw*$srcHeight)/$srcWidth;
$dy=($outHeight-$dh)/2;
}
else { //Empty space on left and right
$dh=$outHeight;
$dw=($dh*$srcWidth)/$srcHeight;
$dx=($outWidth-$dw)/2;
}
}
imagecopyresampled($imgOut,$imgSrc,$dx,$dy,0,0,$dw,$dh,$srcWidth,$srcHeight); //imagecopyresized for lower quality
//Create the thumbnail and destroy everything else
imagepng($imgOut,$output,100);
imagedestroy($imgSrc);
imagedestroy($imgOut);
?>
900 views