473,395 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to Image Upload Crop

I can't load image with javascript. It runs until

alert('$img:'+$(img));

and show alert but doesn't run the function about

$(img).load(function () {

here is my javascript code.

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.  
  3.               $(function() {
  4.                 $("#uploadify").uploadify({
  5.                     'uploader'       : 'uploadify/uploadify.swf',
  6.                     'script'         : '/html/crop/Uploader_files/index.jsp',
  7.                     'cancelImg'      : 'uploadify/cancel.png',
  8.                     'folder'         : 'photos',
  9.                     'queueID'        : 'fileQueue',
  10.                     'auto'           : true,
  11.                     'buttonText'     : 'upload',
  12.                     'queueSizeLimit' : 1,
  13.                     'multi'          : true,
  14.                     'fileDesc'         : 'Support format: jpg / gif / jpeg / png / bmp.',
  15.                     'fileExt'         : '*. jpg; *. gif ; *. jpeg; *. png ',
  16.                     'sizeLimit'      : '99819200',//max size bytes - 800kb
  17.                     'onComplete'       : function (event, queueID, fileObj, response, data) {
  18.  
  19.                     alert("response:"+response.replace(/^\s+|\s+$/g,""));
  20.  
  21.                     alert("fileObj.name:"+fileObj.name);
  22.  
  23.                                             //$('#uploadifyUploader').remove();
  24.  
  25.     //var dataresponse = eval('(' + response + ')');
  26.  
  27.                                             //alert("dataresponse:"+dataresponse);
  28.                                             //alert("dataresponse.result:"+dataresponse.result);
  29.                                             //dataresponse.result
  30.             if( 1==1){ 
  31.                 var filenametmp ="";
  32.                 //(fileObj.name).substring(0,(fileObj.name).lastIndexOf("?");        
  33.             //$('#tempfile').val(filenametmp);
  34.  
  35.     var img = new Image();
  36.     alert('img:'+img);
  37.     alert('$img:'+$(img));
  38.  
  39. $(img).load(function () {
  40.  
  41.         alert('img:'+img);
  42.         $("#cropbox").remove();
  43.         alert('img:'+img);
  44.         $(".jcrop-holder").remove();
  45.                         $(this).attr('id','cropbox');
  46.                                                     $(this).hide();
  47.                                                     $('#image_container').append(this);
  48.  
  49.              $(this).fadeIn().Jcrop({
  50.                 onChange: showPreview,
  51.                                                             onSelect: showPreview,
  52.                                                             aspectRatio: 1,
  53.                                                             onSelect: updateCoords,
  54.                                                             setSelect: [ 0, 0, 150, 150 ]
  55.                                                         });
  56.  
  57.                         $("#preview").remove();
  58.              var _imgprev = $(document.createElement('img')).attr('id','preview').attr('src','/html/uploads/'+fileObj.name);
  59.                         $('#preview_container').append(_imgprev);
  60.  
  61.             alert('_crop_bttn:'+$('#_crop_bttn').length);
  62.  
  63.             if(!$('#_crop_bttn').length){        
  64.                                                         var _crop_bttn = $(document.createElement('input')).attr('id','_crop_bttn').attr('type','submit').val('save');
  65.                                                         var _crop_cancel_bttn = $(document.createElement('input')).attr('id','_crop_cancel_bttn').attr('type','submit').val('cancel');
  66.                                                         _crop_cancel_bttn.click(function(){$('#cropattrform input.jq_step').val('cancel');});    
  67.                                                         _crop_bttn.click(function(){$('#cropattrform input.jq_step').val('process');});    
  68.                                                         $('#cropattrform').append(_crop_bttn).append(_crop_cancel_bttn);
  69.                                                     }
  70.                                                 }).attr('src', '/html/uploads/'+fileObj.name);
  71.                                             }    
  72.                                             else
  73.                                                 alert('error');
  74.                                         },        
  75. 'onError'         : function(event, queueID, fileObj, response, data){alert('error'+response);alert('error'+fileObj.name); }
  76.             });
  77.       });    
  78.  
From the about code starting from
$(img).load(function () {

alert('img:'+img);
......... to

$('#cropattrform').append(_crop_bttn).append(_crop _cancel_bttn);
}
}).attr('src', '/html/uploads/'+fileObj.name);
Does not work

Thanks and Regards,
Yan Paing
May 24 '10 #1
2 4416
RamananKalirajan
608 512MB
Whether its showing any script error on that line?

Thanks and Regards
Ramanan Kalirajan
May 26 '10 #2
Thanks for Reply Ramanankalirajan,
I didn't see any script error on that line when i run it.
I fixed the code and that error is fixed.But preview image alignment is now in problem.

Here is my code .



Expand|Select|Wrap|Line Numbers
  1. <link href="Uploader_files/default.css" rel="stylesheet" type="text/css">
  2. <link href="Uploader_files/uploadify.css" rel="stylesheet"
  3.     type="text/css">
  4. <link rel="stylesheet" href="Uploader_files/jquery.css" type="text/css">
  5. <link rel="stylesheet" href="Uploader_files/demos.css" type="text/css">
  6. <link rel="stylesheet" href="jcrop/jquery.Jcrop.css" type="text/css" />
  7.  
  8.  
  9. <script type="text/javascript" language="javascript" src="Uploader_files/jquery-1.js"></script>
  10. <script type="text/javascript" src="Uploader_files/swfobject.js"></script>
  11. <script type="text/javascript" src="Uploader_files/jquery.js"></script>
  12. <script type="text/javascript" src="uploadify/jquery.uploadify.v2.1.0.min.js"></script>
  13. <script type="text/javascript" src="jcrop/jquery.Jcrop.min.js"></script>
  14. <script type="text/javascript" src="Uploader_files/jquery_002.js"></script>
  15.  
  16.  
  17. <script type="text/javascript">
  18. var imgName;
  19.               $(function() {
  20.                 $("#uploadify").uploadify({
  21.                     'uploader'       : 'uploadify/uploadify.swf',
  22.                     'script'         : '/html/crop/Uploader_files/index.jsp',
  23.                     'cancelImg'      : 'uploadify/cancel.png',
  24.                     'folder'         : 'photos',
  25.                     'queueID'        : 'fileQueue',
  26.                     'auto'           : true,
  27.                     'buttonText'     : 'upload',
  28.                     'queueSizeLimit' : 1,
  29.                     'multi'          : true,
  30.                     'fileDesc'         : 'Support format: jpg / gif / jpeg / png / bmp.',
  31.                     'fileExt'         : '*. jpg; *. gif ; *. jpeg; *. png ',
  32.                     'sizeLimit'      : '99819200',//max size bytes - 800kb
  33.                     'onComplete'       : function (event, queueID, fileObj, response, data) {
  34.  
  35.  
  36.             if( 1==1){ 
  37.                 var filenametmp ="";
  38.  
  39.     var img = new Image();
  40.  
  41. load(img,fileObj,this);
  42.  
  43.                                             }    
  44.                                             else
  45.                                                 alert('error');
  46.                                         },        
  47. 'onError'         : function(event, queueID, fileObj, response, data){alert('error'+response);alert('error'+fileObj.name); }
  48.             });
  49.       });    
  50.             function updateCoords(c)
  51.             {
  52.  
  53.                 $('#x').val(c.x);
  54.                 $('#y').val(c.y);
  55.                 $('#w').val(c.w);
  56.                 $('#h').val(c.h);
  57.  
  58.             };
  59.             function checkCoords()
  60.             {
  61.  
  62.                 if (parseInt($('#w').val())){
  63.                     return true;
  64.                 }    
  65.                 $('#x').val(0);
  66.                 $('#y').val(0);
  67.                 $('#w').val(150);
  68.                 $('#h').val(150);
  69.  
  70.                 return true;
  71.             };
  72.             function showPreview(coords)
  73.             {
  74.                 if (parseInt(coords.w) > 0)
  75.                 {
  76.                     var rx = 100 / coords.w;
  77.                     var ry = 100 / coords.h;
  78.  
  79.                     $('#preview').css({
  80.                         width: Math.round(rx * $imgpos.width) + 'px',
  81.                         height: Math.round(ry * $imgpos.height) + 'px',
  82.                         marginLeft: '-' + Math.round(rx * coords.x) + 'px',
  83.                         marginTop: '-' + Math.round(ry * coords.y) + 'px'
  84.                     });
  85.                 }
  86.             };    
  87.             $imgpos = {
  88.                     width    : '100%',
  89.                     height    : '100%'
  90.             };
  91.  
  92. function load(img,fileObj,_this) {
  93.  
  94.         var _imgContainer = $(document.createElement('img')).attr('src','/html/uploads/'+fileObj.name).attr('id','cropbox');
  95.         imgName=fileObj.name;
  96.         $(".jcrop-holder").remove();
  97.         $('#imgName').val(imgName);
  98.           $('#image_container').append(_imgContainer);
  99.  
  100.      $('#cropbox').fadeIn().Jcrop({
  101.  
  102.             onChange: showPreview,
  103.                                                         onSelect: showPreview,
  104.                                                         aspectRatio: 1,
  105.                                                         onSelect: updateCoords,
  106.                                                         setSelect: [ 0, 0, 100, 100 ]
  107.                                                     });
  108.  
  109.                     $("#preview").remove();
  110.  
  111.  var _imgprev = $(document.createElement('img')).attr('id','preview').attr('src','/html/uploads/'+fileObj.name).attr('name','tempImg');
  112.                     $('#preview_container').append(_imgprev);
  113.  
  114. if(!$('#_crop_bttn').length){        
  115.                                                         var _crop_bttn = $(document.createElement('input')).attr('id','_crop_bttn').attr('type','submit').val('save');
  116.                                                         var _crop_cancel_bttn = $(document.createElement('input')).attr('id','_crop_cancel_bttn').attr('type','submit').val('cancel');
  117.                                                         _crop_cancel_bttn.click(
  118.                                                                 function(){
  119.                                                                     alert('_crop_cancel_bttn click : ');
  120.                                                                     $('#cropattrform input.jq_step').val('cancel');
  121.                                                                 });    
  122.                                                         _crop_bttn.click(function(){
  123.  
  124.                                                             $('#cropattrform input.jq_step').val('process');
  125.                                                             });    
  126.                                                         $('#cropattrform').append(_crop_bttn).append(_crop_cancel_bttn);
  127.                                                     }
  128.  
  129. }
  130.           </script>
May 26 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Aurel | last post by:
Hi, I'd like to crop an image into several others images considering the following : - no quality loss (I'd like to keep exactly the same quality). - total images size must not be too high...
5
by: Kevin Smith | last post by:
Is there a way to "auto-crop" an image in PIL? I have some PNG images with white backgrounds that I want cropped to show only the non-white portion in the center, but I don't see how I can do...
6
by: isaacyho | last post by:
Is there a fast way to crop a vector? I have a vector of size n, and want to reduce it to some subregion (x,y ). Seems like you shouldn't have to recopy all of those elements into a new vector,...
1
by: Jazper | last post by:
hi how can i Insert, change and crop META-Tags auf a Webform programmtechnically? Regards Jazper
3
by: ACaunter | last post by:
Hi there, I was wondering if there was a way to crop a peice of an ASP.Net Image, allowing the user to zoom in on only a section of the picture?? any help would be appreciated!! thanks --...
6
by: John Salerno | last post by:
I might be way off target even looking into this method for what I need to do, but I'm still a little confused about the description of it: crop im.crop(box) => image Returns a rectangular...
2
by: sampath nslabs | last post by:
sir How to crop the image in visual basic 6.0.iam geting in vb.net but i want purelly in vb.plese give the code for that or give me useful snippts.i expecting source code for crop the image .pls...
0
by: brahimbb17 | last post by:
There is no foolproof way to always win when gambling http://crop-finder-for-travian.blogspot.com . That is why it’s called gambling, you take risks and reap the benefits when lady lucks sides by...
1
Thekid
by: Thekid | last post by:
Hi, I have an image similar to a clock, with numbers and letters going around in a circle. I need to extract the numbers and letters from the image and have them print out in a straight line and in...
3
by: fuchsia555 | last post by:
hi is there a code to crop bottom border from an image when creating thumbnail for this image without crop the original image , but just crop 15px bottom border for creating the thumbnails for the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.