tags:

views:

1889

answers:

5
A: 

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.

Dave Markle
+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
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
+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
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
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
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