• PHP kvadrātainu thumbnail griezšana

    PHP kvadrātainu thumbnail griezšana

    function LoadJpeg($imgname)
    {

    $im = @imagecreatefromjpeg($imgname);

    if(!$im)
    {

    $im = imagecreatetruecolor(150, 30);
    $bgc = imagecolorallocate($im, 255, 255, 255);
    $tc = imagecolorallocate($im, 0, 0, 0);

    imagefilledrectangle($im, 0, 0, 150, 30, $bgc);

    imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
    }
    $thumb_size = 100;
    $size = getimagesize($imgname);
    $width = $size[0];
    $height = $size[1];

    if($width> $height) {
    $x = ceil(($width - $height) / 2 );
    $width = $height;
    } elseif($height> $width) {
    $y = ceil(($height - $width) / 2);
    $height = $width;
    }
    $new_im = ImageCreatetruecolor($thumb_size,$thumb_size);
    imagecopyresampled($new_im,$im,0,0,$x,$y,$thumb_size,$thumb_size,$width,$height);

    return $new_im;
    }


1111111