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:
- y_pos
- x_pos
- width
- height
I'm using this upload script:
- <?php
- function __autoload($class_name)
- {
- include_once('./../includes/class_'. strtolower($class_name) . '.php');
- }
- $path = Settings::$include_path."/uploaded/avatar_realsize/";
- $valid_formats = array("jpg", "png", "gif", "bmp","jpeg");
- if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
- {
- $name = $_FILES['photoimg']['name'];
- $size = $_FILES['photoimg']['size'];
- $user_id = $_POST['user_id'];
- if(strlen($name))
- {
- list($txt, $ext) = explode(".", $name);
- if(in_array($ext,$valid_formats))
- {
- if($size>(100*100))
- {
- $actual_image_name = $user_id.".".$ext;
- $tmp = $_FILES['photoimg']['tmp_name'];
- if(move_uploaded_file($tmp, $path.$actual_image_name))
- {
- echo Settings::$url."/uploaded/". $actual_image_name;
- }
- }
- }
- }
- exit;
- }
- ?>
This is the crop:
- jQuery(function($){
- $('#photoimg').live('change', function()
- {
- $("#imageform").ajaxForm({
- success: function(responseText)
- {
- jcrop_api.setImage(responseText);
- }
- }).submit();
- });
- var coord = $('#profielfotoform').attr('rel');
- var existwidth = 0;
- var existheight = 0;
- if(existwidth == '0' && existheight == '0')
- {
- var width = 250;
- var height = 250;
- } else {
- var width = existwidth;
- var height = existheight;
- }
- // Create variables (in this scope) to hold the API and image size
- var boundx,
- boundy,
- // Grab some information about the preview pane
- $preview = $('#preview-pane'),
- $pcnt = $('#preview-pane #preview-container'),
- $pimg = $('#preview-pane #preview-container img'),
- xsize = $pcnt.width(),
- ysize = $pcnt.height();
- console.log('init',[xsize,ysize]);
- jcrop = $('#target').Jcrop({
- setSelect: [width, height, 0, 0],
- minSize: [250, 250],
- onChange: updatePreview,
- onSelect: updatePreview,
- aspectRatio: xsize / ysize
- },function(){
- // Use the API to get the real image size
- var bounds = this.getBounds();
- boundx = bounds[0];
- boundy = bounds[1];
- // Store the API in the jcrop_api variable
- jcrop_api = this;
- });
- function updatePreview(c)
- {
- if (parseInt(c.w) > 0)
- {
- var rx = xsize / c.w;
- var ry = ysize / c.h;
- $pimg.css({
- width: Math.round(rx * boundx) + 'px',
- height: Math.round(ry * boundy) + 'px',
- marginLeft: '-' + Math.round(rx * c.x) + 'px',
- marginTop: '-' + Math.round(ry * c.y) + 'px'
- });
- }
- };
- });
(ajaxForm is a plug-in i'm using.)
And this is the form:
- if(file_exists(Settings::$include_path.'/uploaded/avatar_realsize/'.$row['user_id'].'.png')) { $realavatar = Settings::$url.'/uploaded/avatar_realsize/'.$row['user_id'].'.png';
- }
- <div id="profielblurreffect"></div>
- <div id="profielfotoform">
- <div class="crop-field-info">
- Dit is het veld waar u de afbeelding kunt bijsnijden.<br />
- Door op dit veld te klikken zal het bijsnijden worden geactiveerd.
- </div>
- <div class="preview-pane-info">
- Dit is een voorbeeld van de bijgesneden afbeelding met de afmetingen van<br />250 pixels bij 250 pixels.
- </div>
- <div class="preview-pane-info2">
- Dit is een voorbeeld van de bijgesneden afbeelding met de afmetingen van<br />100 pixels bij 100 pixels.<br />
- Dit is de afmeting die word gebruikt voor de profiel foto.
- </div>
- <div class="preview-pane-info3">
- Dit is een voorbeeld van de bijgesneden afbeelding met de afmetingen van<br />50 pixels bij 50 pixels.
- </div>
- <div class="upload-info">
- Hier kunt u een foto uploaden.
- </div>
- <span class="jcropformtitel">Profielfoto wijzigen '.$adminedit.'</span><img class="help-icon" src="'.Settings::$url.'/images/help-icon.png">
-
- <div id="crop-size">
- <img src="'.$realavatar.'" id="target" alt="Snijvlak" />
- </div>
- <div id="preview-pane">
- <div id="preview-container">
- <img src="'.$realavatar.'" class="jcrop-preview" alt="Preview 250x250" />
- </div>
- </div>
- <form id="imageform" method="post" enctype="multipart/form-data" action="'.Settings::$url.'/js/uploadimage.php">
- <input type="hidden" value="'.$user_id.'" name="user_id" />
- Upload foto <input type="file" name="photoimg" id="photoimg" rel="'.$user_id.'" />
- </form>
- <div id="profielfotoformbuttons">
- <button id="canceleditprofielfoto">Annuleren</button>
- <button id="saveeditprofielfoto">Opslaan</button>
- </div>
- </div>