• png uz jpg ar izgriezšanas funkciju

    function png2jpg($originalFile, $outputFile, $quality, $crop, $crop2, $cirpt) {
    $image = imagecreatefrompng($originalFile);
    if ($crop>0){
    $size = getimagesize($originalFile);
    $width = $size[0];
    $height = $size[1];
    $ww=$crop;
    $hh=$crop2;
    if ($cirpt==1){
    if($width> $height) {
    $x=$width/$ww;
    } else {
    $x=$height/$hh;
    }
    $thumb_size1=ceil($width/$x);
    $thumb_size2=ceil($height/$x);
    } else if ($cirpt==2){
    $thumb_width = $crop;
    $thumb_height = $crop2;
    $width = $size[0];
    $height = $size[1];
    $original_aspect = $width / $height;
    $thumb_aspect = $thumb_width / $thumb_height;
    if ( $original_aspect >= $thumb_aspect )
    {
    // If image is wider than thumbnail (in aspect ratio sense)
    $new_height = $thumb_height;
    $new_width = $width / ($height / $thumb_height);
    }
    else
    {
    // If the thumbnail is wider than the image
    $new_width = $thumb_width;
    $new_height = $height / ($width / $thumb_width);
    }
    $thumb_size1=$crop;
    $thumb_size2=$crop2;
    $x1 = 0 - ($new_width - $thumb_width) / 2;
    $y1 = 0 - ($new_height - $thumb_height) / 8;
    $x=0;
    $y=0;
    } else {
    $new_width = $size[0];
    $new_height = $size[1];
    $width = $size[0];
    $height = $size[1];
    }
    $new_im = ImageCreatetruecolor(($thumb_size1),$thumb_size2);
    imagecopyresampled($new_im,$image,$x1,$y1,$x,$y,$new_width,$new_height,$width,$height);
    imagejpeg($new_im, $outputFile, $quality);
    imagedestroy($new_im);
    } else {
    imagejpeg($image, $outputFile, $quality);
    imagedestroy($image);
    }
    }


  • 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;
    }