Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-07-2013, 05:25 AM   PM User | #1
martynball
Regular Coder

 
Join Date: Nov 2007
Posts: 553
Thanks: 231
Thanked 0 Times in 0 Posts
martynball is an unknown quantity at this point
Cropping an image in browser

Hey, I need to give a user the ability to move a box around over and image to select an area, and then crop the image based on the area within the box.

Facebook has this feature when you change your display picture. What I don't understand is how you get the coordinates of each corner of the box and how Facebook dulls the rest of the image around the box.

I understand how to use the server side code to actually create the image, I just need to use JavaScript to get the coordinates.
martynball is offline   Reply With Quote
Old 01-07-2013, 10:17 AM   PM User | #2
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,455
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
Quote:
Originally Posted by martynball View Post
Hey, I need to give a user the ability to move a box around over and image to select an area, and then crop the image based on the area within the box.

Facebook has this feature when you change your display picture. What I don't understand is how you get the coordinates of each corner of the box and how Facebook dulls the rest of the image around the box.

I understand how to use the server side code to actually create the image, I just need to use JavaScript to get the coordinates.
those numbers are available as event attributes on mouseup, and mousemove event handlers.
clientX et al, just lookup the mouse events.

you can grey out the rest with css:

Code:
#cropbox { box-shadow:0 0 1000px rgba(0,0,0,0.75); cursor: move;  }
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Users who have thanked rnd me for this post:
martynball (01-07-2013)
Old 01-07-2013, 06:57 PM   PM User | #3
martynball
Regular Coder

 
Join Date: Nov 2007
Posts: 553
Thanks: 231
Thanked 0 Times in 0 Posts
martynball is an unknown quantity at this point
the box-shadow doesn't stay within a containing div, it overflows so can't use that. I just used Firebug to look at Facebook's technique, it uses "clip" which is in CSS3 and seems to be supported by all browsers.
martynball is offline   Reply With Quote
Old 01-08-2013, 03:12 PM   PM User | #4
vwphillips
Senior Coder

 
Join Date: Mar 2005
Location: Portsmouth UK
Posts: 4,354
Thanks: 3
Thanked 458 Times in 445 Posts
vwphillips is a jewel in the roughvwphillips is a jewel in the roughvwphillips is a jewel in the rough
http://www.vicsjavascripts.org.uk/Im...ds/130108A.htm


http://www.vicsjavascripts.org.uk/Im...eMapCoords.htm
__________________
Vic

God Loves You and will never love you less.

http://www.vicsjavascripts.org.uk/

If my post has been useful please donate to http://www.operationsmile.org.uk/

Last edited by vwphillips; 01-09-2013 at 09:11 AM..
vwphillips is offline   Reply With Quote
Old 01-08-2013, 06:23 PM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,187
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
I created my own a couple of years ago. I just used a <div> with a boundary and transparent contents and then allowed the user to drag the bottom right corner to enlarge/shrink/resize the bounds and drag any place else to move the "box".

I didn't bother "shading" the image, but I could have easily enough.

It wasn't pretty, but it worked quite well.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 01-09-2013, 09:13 AM   PM User | #6
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,455
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
Quote:
Originally Posted by martynball View Post
the box-shadow doesn't stay within a containing div, it overflows so can't use that. I just used Firebug to look at Facebook's technique, it uses "clip" which is in CSS3 and seems to be supported by all browsers.
it depends on box vs inline. a relative container should cut off an absolute child's shadow without forcing AP on everything...
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:43 PM.


Advertisement
Log in to turn off these ads.