You can put the img tag in a div tag and do both, but I would recommend against scaling images in the browser. It does a lousy job most of the time because browsers have very simplistic scaling algorithms. Better to do your scaling in Photoshop or ImageMagick first, then serve it up to the client nice and pretty.
A:
Dave Markle
2009-01-29 20:40:32
+4
A:
You could use a combination of both methods eg.
<div class="crop">
<img src="..." alt="..." />
</div>
CSS:
.crop { width: 200px; height: 150px; overflow: hidden; }
.crop img { width: 400px; height: 300px; margin: -75px 0 0 -100px; }
You can use negative margin to move the image around within the div.
sanchothefat
2009-01-29 20:42:52
Note that if you set position:relative on the contained image, you'll need to set position:relative on the containing div. If you don't, I've found that IE won't actually clip the image.
Frank Schwieterman
2009-06-26 22:56:31
+1
A:
<style>
.imgContainer{
overflow:hidden;
width:200px;
height: 100px;
}
.imgContainer img{
width:200px;
hieght:120px;
}
</style>
<div class="imgContainer">
<img src="imageSrc" />
</div>
The containing div with essentially crop the image by hiding the overflow.
Kelly Anderson
2009-01-29 20:44:51
A:
What I've done is to create a server side script that will resize and crop a picture on the server end so it'll send less data across the interweb.
It's fairly trivial, but if anyone is interested, I can dig up and post the code (asp.net)
Rob
2009-01-29 20:46:05
CGI is probably the most portable method (and bandwidth-efficient), unless the OP intends to allow the user to perform their own resizing and cropping via Javascript.
strager
2009-01-29 20:48:11
A:
Rob, I know it is a bit old thread, but maybe You could help me... if You have that code any more... i'd be grateful for it :) Can You write it down, or sent me on my e-mail address (drartoor[at]o2.pl)
Thanks in advance
Sorry for my English - it's not my native language :)
artoor
2010-07-13 16:27:01