RSS link icon

Css dynamic round image corners 

 

This is really an alternative way of making rounded corners on images online.

I think this way is unique, I have never seen people making rounded corners on images this way, or tutorial on doing it this way, so I made it my self.

There are good and bad things about my way of doing things.

The bad thing is, you cant right click the image and get its properties etc.

The good thing about that is, it gives a small copyright protection, (people cant right click your images and choose save image, they would only get the frame).

 

image rounded corners

 

First I will explain how this method works so you can understand what we are about to do.

We will have our images, all at the same size, I made mine 140 x 110 px.

Then we will make another image using Photoshop, this image will be a png or gif file, because those formats supports transparency, only graphic shown will the the four rounded corners, and thats what we need, because we will put the image in our html file, then position the transparent image on top of it.

 

image rounded corners

Now down to business, we will start by making an image 140 x 110 px in Photoshop, just open the image and go to image -> image size and give it settings as shown below.

image rounded corners

Now we will make the image to go on top of our image, it has to be the same size as our image, 140 x 110 px.

Start with a white background layer, then draw a rounded rectangle shape in a new layer, resize it to fit in our stage. Hold down ctrl and click the layer in the layers panel to load the selection, now you can delete the rounded rectangle again, we only needed the selection.

image rounded corners

So select the white background layer and hit delete and you will end up with only four corners and a transparent middle. Now save the image as png24 supporting transparent. (ps you can download the project files at the bottom).

Now to the code part.

To make this easy I only used 1 html file and placed the css code in the html file, (usually I would use an external css file to separate code).

Place your html file in the same folder as your image and your frame image from before.

Write the following code in your html file and save it. Explanations will be in the code be make it easier to understand as we follow.



//Remember to put these styles in the header section between   tags as you can see from the project files
//Now the last part is to define our objects, first a div container surrounding the content. then our image, and remember to give it the id specified in the styles
//finally the frame image, just placed next to our content image, because we have already positioned it within our styles.

Download the project file here.

 

I really hope you learned something here, I did, some of you might think why all the when you can just go to Photoshop and give all your images rounded corners. The answer is, if you have 1000 thumbnail images and want to give them rounded corners, that might take time, and what if you only needed the rounded corners for one way of presentation it, and in another place you want the original, then this "dynamic" way is better. I worked for me.


Admin Bob says: Monday, September 22, 2008

Not really, thats why I also will only recommend this for speffic cases, As I did have one case where I needed it. But for future projects, I will use other methods for better compatability


Jazmin says: Thursday, September 18, 2008

This method does work nicely, but as you said, it renders the image unclickable (including the left-clicking required if you were to link the image).

Any ideas on how to get around this


Admin Bob says: Wednesday, September 03, 2008

what browser are you testing it in it is not supported in all browsers.


Kmnlive says: Sunday, August 31, 2008

After converting it to .gif still it doesnChr(34)t work, rather it shows my original rectangular image! Please help.


JP says: Wednesday, April 16, 2008

But this is only gonna work if you have a even background (like one color).

What if you have a gradient background
Have anyone an idea

But it works very good otherwise.
Thanks for the tutorial.


Admin Bob says: Monday, March 31, 2008

hi Lilfade, thanks, seems I should have done a bit more research there, you found a solution :-) great!


Lilfade says: Monday, March 31, 2008

Try adding this to the page

!--[if lt IE 8]
script src="http://ie7-js.googlecode.com/svn/version/2.0(beta3)/IE8.js" type="text/javascript"/script
![endif]--

and then add name the images -trans.png
eg. frame.png -- frame-trans.png

link: http://code.google.com/p/ie7-js/

:D


Marina says: Wednesday, February 13, 2008

I change to .gif and it is work. Thanks.


Admin Bob says: Wednesday, February 13, 2008

Now I checked up on it, and IE 6.0 does not support transparency for png files, but it should be fixed if you convert the frame.png file to a gif file.


Admin Bob says: Tuesday, February 12, 2008

Hmm, My guess is, but iChr(34)m not sure, that previous versions of IE is not supporting png transparency. I will check up on that tomorrow. (A workaround could be to make it a gif file instead).

  Next 


 

 

 

 4

 
 
   Web Premium
 
 

All rights reserved, Copyright 2008. Contact