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