Jag förstår inte rikitgt varför man gjort funktionen ImageCopyResampleBicubic() Det ser jobbigt ut att bara titta på den.
Går det inte lika bra att använda imagecopyresampled eller är det något speciellt du är ute efter mer än att bara skala bilden?
jag använder följande skript för generering av tumnaglar:
<?
// scalePic(infil, utfil, max X-storlek, max Y-storlek, kvalitet (0-100));
function scalePic($filnamn, $nyttfilnamn, $maxX, $maxY, $kvalitet = 75) {
$im = ImageCreateFromJPEG($filnamn);
$im_width=imageSX($im);
$im_height=imageSY($im);
if ($maxX > $maxY) {
$factor = $maxX/$im_width;
$new_width = $maxX;
$new_height = $im_height * $factor;
}
else {
$factor = $maxY/$im_width;
$new_width = $maxY;
$new_height = $im_height * $factor;
}
// resize
$new_im=imagecreatetruecolor($new_width,$new_height);
ImageCopyResampleBicubic($new_im,$im,0,0,0,0,$new_width,$new_height,$im_width,$im_height);
// output
Imagejpeg($new_im,$nyttfilnamn,$kvalitet); // quality 75
// cleanup
ImageDestroy($im);
ImageDestroy($new_im);
}
function ImageCopyResampleBicubic ($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
/*
port to PHP by John Jensen July 10 2001 -- original code (in C, for the PHP
GD Module) by [email]jernberg@fairytale.se[/email]
*/
{
for ($i = 0; $i < 256; $i++) { // get pallete. Is this algoritm correct?
$colors = ImageColorsForIndex ($src_img, $i);
ImageColorAllocate ($dst_img, $colors['red'], $colors['green'], $colors['blue']);
}
$scaleX = ($src_w - 1) / $dst_w;
$scaleY = ($src_h - 1) / $dst_h;
$scaleX2 = $scaleX / 2.0;
$scaleY2 = $scaleY / 2.0;
for ($j = $src_y; $j < $dst_h; $j++) {
$sY = $j * $scaleY;
for ($i = $src_x; $i < $dst_w; $i++) {
$sX = $i * $scaleX;
$c1 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, (int) $sX, (int) $sY + $scaleY2));
$c2 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, (int) $sX, (int) $sY));
$c3 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, (int) $sX + $scaleX2, (int) $sY + $scaleY2));
$c4 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, (int) $sX + $scaleX2, (int) $sY));
$red = (int) (($c1['red'] + $c2['red'] + $c3['red'] + $c4['red']) / 4);
$green = (int) (($c1['green'] + $c2['green'] + $c3['green'] + $c4['green']) / 4);
$blue = (int) (($c1['blue'] + $c2['blue'] + $c3['blue'] + $c4['blue']) / 4);
$color = ImageColorClosest ($dst_img, $red, $green, $blue);
ImageSetPixel ($dst_img, $i + $dst_x, $j + $dst_y, $color);
}
}
}
?>
När jag anropar skriptet får jag följande fel:
Fatal error: Maximum execution time of 30 seconds exceeded in /home/ServerRoots/www/album/gd_source.php on line 60
Raderna kring 60:
$c1 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, (int) $sX, (int) $sY + $scaleY2));
$c2 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, (int) $sX, (int) $sY));
$c3 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, (int) $sX + $scaleX2, (int) $sY + $scaleY2));
$c4 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, (int) $sX + $scaleX2, (int) $sY));
vad beror det på? finns nåt sätt att få fram ngn debugginginfo? ImageColorsForIndex() samt ImageColorAt() har jag provat var för sig utan att kunna reproducera felet.
/r
under tiden jag kör php-filen tar apache drygt 90 % av cpu:n. någonting är ju märkligt här! :)
