Set the <img src
to a partial image from a bigger image? There is no way.
You already have the answer: use the background
CSS property and position it to the desired coordinates. Note: You can assign background images to the <img>
tag if that helps you at all.
Just for kicks, as an alternate solution: You could append your image with a query string that contains the coordinates and size:
<img src="/my_image.jpg?x=400&y=220&width=200&height=120">
...then use .htaccess
to send this request to a server side script that processes the image and outputs the partial image (but that's another topic altogether).
This post might help you with the .htaccess
bit, should you choose to implement it:
It really sounds like you want to use CSS sprites, there are a number of tutorials on this, here's one: