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
https://forums.phpfreaks.com/topic/34989-pixel-picking-with-javascript/
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.
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.