JCrop - posting a cropped image

JCrop - posting a cropped image

Hello,

This is the first time i'm using the JCrop plug-in and i have a couple of questions. I am trying to create a pop-up where you can upload an image and crop it. The full image gets posted to a folder where the real image stays so you can edit the crop after the uploading. (this works)

The pop-up has a save button which should submit the cropped image to another folder where the cropped images are saved. How do i submit an cropped image to a folder?
I have 4 rows in my database which are to store the coordinates and height/width.

Those are:
  1. y_pos
  2. x_pos
  3. width
  4. height

I'm using this upload script:
  1. <?php
  2. function __autoload($class_name)
  3. {
  4. include_once('./../includes/class_'. strtolower($class_name) . '.php');
  5. }

  6. $path = Settings::$include_path."/uploaded/avatar_realsize/";
  7. $valid_formats = array("jpg", "png", "gif", "bmp","jpeg");
  8. if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
  9. {
  10. $name = $_FILES['photoimg']['name'];
  11. $size = $_FILES['photoimg']['size'];
  12. $user_id = $_POST['user_id'];

  13. if(strlen($name))
  14. {
  15. list($txt, $ext) = explode(".", $name);
  16. if(in_array($ext,$valid_formats))
  17. {
  18. if($size>(100*100))
  19. {
  20. $actual_image_name = $user_id.".".$ext;
  21. $tmp = $_FILES['photoimg']['tmp_name'];
  22. if(move_uploaded_file($tmp, $path.$actual_image_name))
  23. {
  24. echo Settings::$url."/uploaded/". $actual_image_name;
  25. }
  26. }
  27. }
  28. }
  29. exit;
  30. }
  31. ?>

This is the crop:
  1. jQuery(function($){
  2. $('#photoimg').live('change', function()
  3. {
  4. $("#imageform").ajaxForm({
  5. success: function(responseText)
  6. {
  7. jcrop_api.setImage(responseText);
  8. }
  9. }).submit();
  10. });

  11. var coord = $('#profielfotoform').attr('rel');

  12. var existwidth = 0;
  13. var existheight = 0;

  14. if(existwidth == '0' && existheight == '0')
  15. {
  16. var width = 250;
  17. var height = 250;
  18. } else {
  19. var width = existwidth;
  20. var height = existheight;
  21. }

  22. // Create variables (in this scope) to hold the API and image size
  23. var boundx,
  24. boundy,

  25. // Grab some information about the preview pane
  26. $preview = $('#preview-pane'),
  27. $pcnt = $('#preview-pane #preview-container'),
  28. $pimg = $('#preview-pane #preview-container img'),

  29. xsize = $pcnt.width(),
  30. ysize = $pcnt.height();

  31. console.log('init',[xsize,ysize]);
  32. jcrop = $('#target').Jcrop({
  33. setSelect: [width, height, 0, 0],
  34. minSize: [250, 250],
  35. onChange: updatePreview,
  36. onSelect: updatePreview,
  37. aspectRatio: xsize / ysize
  38. },function(){
  39. // Use the API to get the real image size
  40. var bounds = this.getBounds();
  41. boundx = bounds[0];
  42. boundy = bounds[1];
  43. // Store the API in the jcrop_api variable
  44. jcrop_api = this;
  45. });

  46. function updatePreview(c)
  47. {
  48. if (parseInt(c.w) > 0)
  49. {
  50. var rx = xsize / c.w;
  51. var ry = ysize / c.h;

  52. $pimg.css({
  53. width: Math.round(rx * boundx) + 'px',
  54. height: Math.round(ry * boundy) + 'px',
  55. marginLeft: '-' + Math.round(rx * c.x) + 'px',
  56. marginTop: '-' + Math.round(ry * c.y) + 'px'
  57. });
  58. }
  59. };
  60. });
(ajaxForm is a plug-in i'm using.)

And this is the form:
  1. if(file_exists(Settings::$include_path.'/uploaded/avatar_realsize/'.$row['user_id'].'.png')) {             $realavatar = Settings::$url.'/uploaded/avatar_realsize/'.$row['user_id'].'.png'; 
  2.         }
  3.         <div id="profielblurreffect"></div>
  4. <div id="profielfotoform">
  5. <div class="crop-field-info">
  6. Dit is het veld waar u de afbeelding kunt bijsnijden.<br />
  7. Door op dit veld te klikken zal het bijsnijden worden geactiveerd.
  8. </div>
  9. <div class="preview-pane-info">
  10. Dit is een voorbeeld van de bijgesneden afbeelding met de afmetingen van<br />250 pixels bij 250 pixels.
  11. </div>
  12. <div class="preview-pane-info2">
  13. Dit is een voorbeeld van de bijgesneden afbeelding met de afmetingen van<br />100 pixels bij 100 pixels.<br />
  14. Dit is de afmeting die word gebruikt voor de profiel foto.
  15. </div>
  16. <div class="preview-pane-info3">
  17. Dit is een voorbeeld van de bijgesneden afbeelding met de afmetingen van<br />50 pixels bij 50 pixels.
  18. </div>
  19. <div class="upload-info">
  20. Hier kunt u een foto uploaden.
  21. </div>
  22. <span class="jcropformtitel">Profielfoto wijzigen '.$adminedit.'</span><img class="help-icon" src="'.Settings::$url.'/images/help-icon.png">
  23. <div id="crop-size">
  24. <img src="'.$realavatar.'" id="target" alt="Snijvlak" />
  25. </div>

  26. <div id="preview-pane">
  27. <div id="preview-container">
  28. <img src="'.$realavatar.'" class="jcrop-preview" alt="Preview 250x250" />
  29. </div>
  30. </div>

  31. <form id="imageform" method="post" enctype="multipart/form-data" action="'.Settings::$url.'/js/uploadimage.php">
  32. <input type="hidden" value="'.$user_id.'" name="user_id" />
  33. Upload foto <input type="file" name="photoimg" id="photoimg" rel="'.$user_id.'" />
  34. </form>
  35. <div id="profielfotoformbuttons">
  36. <button id="canceleditprofielfoto">Annuleren</button>
  37. <button id="saveeditprofielfoto">Opslaan</button>
  38. </div>
  39. </div>
    • Topic Participants

    • 57417