• Attēla kvadrāta thumbnail izgriezšana PHP

    function LoadJpeg($imgname,$izmers)
    {
    $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);
    }
    $size = getimagesize($imgname);
    $width = $size[0];
    $height = $size[1];
    if($width> $height) {
    $x = ceil(($width - $height) / 2 );
    $width = $height;
    } else{
    $y = ceil(($height - $width) / 2);
    $height = $width;
    }
    $thumb_size1=$izmers;
    $thumb_size2=$izmers;

    $new_im = ImageCreatetruecolor(($thumb_size1),$thumb_size2);
    imagecopyresampled($new_im,$im,0,0,$x,$y,$thumb_size1,$thumb_size2,$width,$height);

    return $new_im;
    }


1111111