Jump to content

pixel picking with javascript


aunquarra

Recommended Posts

I'm working on a php-driven integrated image upload/control system that generates various image sizes, which in and of itself is pretty simple.

What I'm working on now is making the thumbnail generation a user-interactive system. Specifically, they can pick a region of the image to be targeted for the thumbnail. On the php side, this, again, will be relatively simple. But the only option I've found for picking the target area is to image map every pixel so I know where a person clicked for the corners of the target area. So much for efficiency.

So I figured javascript could have a much more efficient solution, and to my surprise, I found no help from the Oracle (what my wife and I call Google). Does anyone here know a way javascript can post an X and Y position of an image to a form onClick?
Link to comment
Share on other sites

Well you'd have to add an event listener to your image then store the mouse x,y on mouse down and the mouse x,y on mouse release. That would let you draw a rectangle and send back to php which parts of your image to crop. But it wouldn't give the user any visual feedback. I guess you could position a div that only had borders right over the box you just drew.
Link to comment
Share on other sites

My plan was to have JS or whatever client-side code is running post the x and y position to a form and submit. Then, I'd use PHP to superimpose an X or whatever over the spot, then they'd click the other corne, which would post in the same manner.

It's not as intuitive as I'd like, but when you know no client-side stuff at all, you do as much with server side as you can.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.