Welcome Guest, Not a member yet? Register   Sign In
How to redirect user to the crop image?
#1

[eluser]Unknown[/eluser]
Hi, my application work like this:

User can view the uploaded image by other users. User have the option to crop the image before download (right click->save as).

My problem is:

1.How to redirect to the cropped image after user submit?
2.If other user also use the crop image function,the cropped image by other use will be replaced by new one. How to prevent this?

Thanks in advance. Newbie here.

This is my controller (upload.php):

Code:
function cropimage()
{

        $this->load->view('cropimage'); //cropimage

}

function do_cropimage()
{
        $this->load->model('upload_model');
        $this->upload_model->do_cropimage();
        $this->cropimage();

}

This is my model (upload_model.php):

Code:
function do_cropimage()
    {

        $source = "./uploads/images/Jellyfish.jpg";
        $des_path = "./uploads/images/convert/Jellyfish.jpg";


        //set image library configuration
        $config['image_library'] = 'imagemagick';
        $config['library_path'] = 'C:\imagemagick';
        $config['maintain_ratio'] = false;
        $config['source_image'] = $source;
        $config['new_image'] = $des_path;
        $config['x_axis'] = $this->input->post('x');
        $config['y_axis'] = $this->input->post('y');
        $config['width'] = $this->input->post('w');
        $config['height'] = $this->input->post('h');

        $this->load->library('image_lib', $config);


        if (!$this->image_lib->crop()) {
            echo $this->image_lib->display_errors();
        }


    }
#2

[eluser]jedd[/eluser]
Hi cyberflyx and welcome to the CI forums,

[quote author="cyberflyx" date="1270216547"]
1.How to redirect to the cropped image after user submit?
2.If other user also use the crop image function,the cropped image by other use will be replaced by new one. How to prevent this?
[/quote]

If each user of the system can crop any given image to any given size - then you either need to cache those images, track them according to each user, or keep a record of each user's cropping preferences for each image. Depends if you think disk or CPU is more expensive (in turn this depends on what kind of activity you anticipate on your site).

Can each user have more than one version (cropping settings) for each picture? If they can't, then you just track each image and each user - if you're caching these, have a directory containing images (sub-directories named according to the image ID), and in there have User-ID named cache files, or if you want to get fancy, cropping-sized names (640x480.jpg, say) .. though if any user can make any sized crop this could get a bit big.

For knowing how to redirect to the cropped image .. this seems pretty straightforward - just img src to that user's version of the image when showing a given image. If the user doesn't have an image in there, then they see the original. Or something like that.
#3

[eluser]Unknown[/eluser]
hi thanks for the reply and the welcome. actually i have zero knowledge about caching, so i only understand a little bit on your explanation.

Basically what i want to achieve is exactly same as this demo:
http://deepliquid.com/projects/Jcrop/dem...=live_crop

The difference is only the crop dimension is not fixed.

This is the php code for the demo:

Code:
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
    $targ_w = $targ_h = 150;
    $jpeg_quality = 90;

    $src = 'demo_files/flowers.jpg';
    $img_r = imagecreatefromjpeg($src);
    $dst_r = ImageCreateTrueColor( $targ_w, $targ_h );

    imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
    $targ_w,$targ_h,$_POST['w'],$_POST['h']);

    header('Content-type: image/jpeg');
    imagejpeg($dst_r,null,$jpeg_quality);

    exit;
}
#4

[eluser]jedd[/eluser]
Apologies for tardy response - I was hoping someone else who'd done something similar may have popped in.

Have you read up a bit on caching options?

Much of the magic of the deepliquid page seems to be javascript - the PHP side of things looks to be fairly straightforward (I would think).

You might want to use the Input class rather than fiddling with $_POST directly.




Theme © iAndrew 2016 - Forum software by © MyBB