Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

croppic plugin code working for below 1 MB image,a bow 1 MB a loader still to be loading #275

Open
vivekRudiment opened this issue Oct 14, 2017 · 1 comment

Comments

@vivekRudiment
Copy link

I am able to crop images from 50K to 10 mb with no problem. When I transfer the trigram to the VPS server at Hostgater, The cropping process never finishes. The “ bubbles” never stop. I configer the following setting on my VPS Server max_execution_time => 300,memory_limit => 1000,post_max_size => 1000,max_input_time=>60 any thing else i missed please help. check the problem on following link https://www.boats4sale.com/b4sell/individual/dashbaord/editListing/684 username => Ajay@1234567890 password => Ajay@1234567890 Also Find the code i used
public function img_crop_to_file() {
$imgUrl = $_POST['imgUrl'];
// original sizes
$imgInitW = $_POST['imgInitW'];
$imgInitH = $_POST['imgInitH'];
// resized sizes
$imgW = $_POST['imgW'];
$imgH = $_POST['imgH'];
// offsets
$imgY1 = $_POST['imgY1'];
$imgX1 = $_POST['imgX1'];
// crop box
$cropW = $_POST['cropW'];
$cropH = $_POST['cropH'];
// rotation angle
$angle = $_POST['rotation'];

    $jpeg_quality = 50;

    $output_filename = "temp/croppedImg_".rand();

    // uncomment line below to save the cropped image in the same location as the original image.
    //$output_filename = dirname($imgUrl). "/croppedImg_".rand();

    $what = getimagesize($imgUrl);

    switch(strtolower($what['mime']))
    {
        case 'image/png':
            $img_r = imagecreatefrompng($imgUrl);
            $source_image = imagecreatefrompng($imgUrl);
            $type = '.png';
            break;
        case 'image/jpeg':
            $img_r = imagecreatefromjpeg($imgUrl);
            $source_image = imagecreatefromjpeg($imgUrl);
            error_log("jpg");
            $type = '.jpeg';
            break;
        case 'image/gif':
            $img_r = imagecreatefromgif($imgUrl);
            $source_image = imagecreatefromgif($imgUrl);
            $type = '.gif';
            break;
        default: die('image type not supported');
    }
    //Check write Access to Directory
    if(!is_writable(dirname($output_filename))){
    /*$response=array();*/
        $response = Array(
            "status" => 'error',
            "message" => 'Can`t write cropped File'
        );    
    }else{

        // resize the original image to size of editor
        $resizedImage = imagecreatetruecolor($imgW, $imgH);

        imagecopyresampled($resizedImage, $source_image, 0, 0, 0, 0, $imgW, $imgH, $imgInitW, $imgInitH);
        // rotate the rezized image
        $rotated_image = imagerotate($resizedImage, -$angle, 0);
        //$rotated_image = $angle == 0 ? $resizedImage : imagerotate($resizedImage, -$angle, 0);
        // find new width & height of rotated image
        $rotated_width = imagesx($rotated_image);
        $rotated_height = imagesy($rotated_image);
        // diff between rotated & original sizes
        $dx = $rotated_width - $imgW;
        $dy = $rotated_height - $imgH;
        // crop rotated image to fit into original rezized rectangle
        $cropped_rotated_image = imagecreatetruecolor($imgW, $imgH);
        imagecolortransparent($cropped_rotated_image, imagecolorallocate($cropped_rotated_image, 0, 0, 0));
        imagecopyresampled($cropped_rotated_image, $rotated_image, 0, 0, $dx / 2, $dy / 2, $imgW, $imgH, $imgW, $imgH);
        // crop image into selected area

        $final_image = imagecreatetruecolor($cropW, $cropH);
        imagecolortransparent($final_image, imagecolorallocate($final_image, 0, 0, 0));
        // if image width is smaller than defined crop field or not

if($imgW < $cropW){
$dst_x = $imgX1;
$dst_y = $imgY1;
$src_x = $src_y = 0;
$width = $imgW;
$height = $imgH;
}else{
$dst_x = $dst_y = 0;
$src_x = $imgX1;
$src_y = $imgY1;
$width = $cropW;
$height = $cropH;
}
imagecopyresampled($final_image, $cropped_rotated_image, 0, 0, $imgX1, $imgY1, $cropW, $cropH, $cropW, $cropH);
/imagecopyresampled($final_image, $cropped_rotated_image, $dst_x, $dst_y, $src_x, $src_y, $width, $height, $width, $height);/
// finally output png image
//imagepng($final_image, $output_filename.$type, $png_quality);
imagejpeg($final_image, $output_filename.$type, $jpeg_quality);
$response = Array(
"status" => 'success',
"url" => base_url().$output_filename.$type
);
}

    print json_encode($response);
}
@kildeby
Copy link

kildeby commented Feb 6, 2018

+1 - cant get this to work... Any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants