开发者

cropping and ajax uploading

开发者 https://www.devze.com 2023-01-21 05:54 出处:网络
i 开发者_C百科want to upload profile pic like facebook and ajaxupload the image and crop with the fix size

i 开发者_C百科want to upload profile pic like facebook and ajax upload the image and crop with the fix size and ajax upload to server . in jquery ,php ,

how can i do it ?

thanks rahul


One option is to crop the picture after it's uploaded. Cropping the picture on the client side might get tricky.

PHP & jQuery image upload and crop

PHP file upload tutorial

File uploading guidelines in PHP manual


I had working the same scenario, The steps are below

1) I uploaded image through ajax image uploader (http://valums.com/ajax-upload/)

2) initialised jCrop (http://deepliquid.com/content/Jcrop.html) in the success event of step1 (success event means while I upload image through ajax I got success event).

3).then from jCrop got selected area and also saved it with ajax. Snippet for it is here...

 Simple cropping code for PHP (requires the gd extension)

<?php

$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);

?>

and it works like a charm...

If need any help feel free to ask.

0

精彩评论

暂无评论...
验证码 换一张
取 消