Rounded corners on images

Author Message

risto CMS user

Monday 03 July 2006 5:22:29 am

Is there a way of setting rounded corners on renderd images?
I'd like to see this done automaticaly. with the same curve.
Has anyone tried this? or do you know if it at all is posible?

Nathan Kelly

Monday 03 July 2006 7:20:23 am

Hi Risto,

theres a couple of ways to do this, it will depend on what your preference is though, what I mean by that is for each option there is a sacrifice.

Option 1:

Use absolutely positioned span tags within relatively positioned elements (div's p's etc) like so -

<div class="relative-element">
    <img src="whateverwhereever.gif" alt="yeh whatever" />
    <span class="mask-1"></span>
    <span class="mask-2"></span>
    <span class="mask-3"></span>
    <span class="mask-4"></span>
</div>

In your CSS:

div.relative-element {
position:relative;
width:##px;
height:##px;
}

div.relative-element span {
position:absolute;
background-repeat:no-repeat;
background-position:top left;
}

span.mask-1 {
top:0;
left:0;
width:##px;
height##px;
display:block;
background-image:url(yourimageurl.gif/png);
}
/* repeat that for all of your corner masks i.e., 2 top right, 3 bottom right, 4 bottom left...*/

The down side to this is excess mark-up, and if you use html tidy it will throw warnings for empty spans...

Option 2:

Use some JavaScript to apply the corners -

I'm just going to point to a good example of this as I don't have the time to go into it too deep...

http://www.456bereastreet.com/archive/200505/transparent_custom_corners_and_borders/

The downside to this is you rely on JavaScript being enabled on everyone's browser (rarely disabled though).

My preference is the first way, I don't like putting too much faith in JavaScript, that said I'm using both methods on different sites.

Need any more help let me know!

Pardon me while I burst into flames...

André R.

Monday 03 July 2006 7:36:30 am

Then there is the #3 way.
make imagemagic do the job,

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Nathan Kelly

Monday 03 July 2006 7:52:03 am

True André, I agree there are more ways to do rounded corners than my examples.

The main reason I would opt for the overlay style however is if I later decided I wanted my site to have images with square corners I'd need only take my JavaScript off or remove my extra spans, whereas with the imagemagic option I would need to re upload every image!

Pardon me while I burst into flames...

Mark Marsiglio

Monday 03 July 2006 8:23:42 am

It seems that if you could make the rounded corner application part of an eZ Image Alias that the original, square cornered image would still be retained for use in other applications.

Can eZ Image Alias instructions for rounded corners be contained in the image.ini?

http://www.thinkcreative.com
Turning Ideas Into Strategic Solutions

André R.

Monday 03 July 2006 10:38:46 am

Nathan: The orginal image should still be untouched, so you 'only' need to clear the image cache.

Mark: If this involves prosessing images for runded corners on every page hit, it would be a bad idea..

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Nathan Kelly

Monday 03 July 2006 5:20:04 pm

Good point, I didn't think of that.

Pardon me while I burst into flames...

risto CMS user

Tuesday 29 August 2006 8:50:39 am

would someone mind showing how this is don in ez and imagemagic?

I found this

composite -gravity NorthEast rounded-ne.png lake.png lake-1.png
composite -gravity NorthWest rounded-nw.png lake-1.png lake-2.png
composite -gravity SouthEast rounded-se.png lake-2.png lake-3.png
composite -gravity SouthWest rounded-sw.png lake-3.png lake-4.png 

I just dont know how to add this to a filder.

Softriva .com

Monday 19 February 2007 10:40:12 am

risto,

were you able to do it in ez and imagemagick?

OOzy

paul bolger

Tuesday 20 February 2007 4:19:06 pm

Hi OOzy

Bruce Morrison and I have managed to get rounded corners working with ImageMagick. I've written a howto, which may get updated. But here it is:

**************************************************************
Rounded corners on images

There are a number of ways of approaching this problem.

It is possible to overlay a mask (a second image with a transparent centre) in an overlaid div, but this solution has one big drawback: Internet Explorer has patchy support for the only image format which has full alpha support, png24. Which means you are stuck with using a gif, and with jagged edges.

A much better way is to get ImageMagick, one of the graphics processors included with EzPublish, to do the work. It is theoretically possible to get ImageMagick to measure the picture and draw the mask, but this is complicated (if anyone gets it to work please let us know). These discussions may be a good starting place if you feel like taking this to the next level:

http://www.imagemagick.org/Usage/thumbnails/#rounded_border

This section of the ImageMagick useage manual gives details on this, but there are hurdles which would need to be overcome, such as getting ImageMagick in EzPublish to read external vector files (.mvg)

and some more discussion here.

http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=8401

For my particular use case we needed the resulting images to conform to an exact size, so rather than tackling the really hard stuff I elected to get ImageMagick to pull a png24 matt image from the design directory and overlay it on the source image. This is a simpler version of the technique described here:

http://www-128.ibm.com/developerworks/library/l-graf2/?ca=dgr-lnxw15GraphicsLine

but as the final image size is pre-determined there is no need to add the corners individually.

The first thing you'll need to do is to establish whether the version of ImageMagick supports the -composite command. In the case of our host, Atvert Systems, we discovered that they were running the default version which shipped with the operating system - 6.0.7.1-16. (and this situation is quite likely for a professional hosting environment where system stability is more of a priority than having the latest versions of all components)

Luckily Karl, who runs Atvert, was very helpful in identifying the problem and he quickly upgraded ImageMagick to version 6.3.2.7-1, which supports the necessary commands.

The next step is to make a test graphic, you can skip this if you are feeling really sure of yourself but I'd recommend it - you'll probably save yourself a few headaches. Make a two layer Photoshop (but make sure you convert the background layer to an normal one in PS's case) or Gimp file, put the word 'front' on one layer and the work 'back' on another, both with transparent backgrounds. Export the two layers as png24s with transparency. Put the 'front' one in your siteaccess images folder - that will eventually be your matt.

You now need to find out the 'fully qualified path' to that folder. It won't be the ftp path. In our case in involved prepending /var/www/html/ to the address you see in an ftp client. It's probably best to contact your hosting provider on this, unless you feel like a lot of guessing.

Next, open image.ini.append.php. you can do this in either the siteaccess copy or the override copy. Just don't do it in both ! :)

The first thing to add is the filter definition, it goes in the [ImageMagick]
section:

[ImageMagick]
Filters[]=rounded=-compose dst-over -composite -gravity NorthWest /var/www/html/ ... more path goes here ... /design/news_site/images/picmask.png

This makes a filter called 'rounded', makes the destination go over the source, references the overlay to the top left corner and calls the matt image

The -gravity switch may not be necessary.

Next, make an alias for the image which will use the filter:

[AliasSettings]
AliasList[]=mypicturewitharoundedborder

Finally, add the filters to the alias;

[mypicturewitharoundedborder]
Filters[]=geometry/scalewidth=156 Filters[]=geometry/crop=156;90;0;0
Filters[]=rounded=

The first two filters resize the image to a width of 156px and then crop it to 156px by 90px. This means no matter what a user uploads they will get the same image size.

The final filter applies the mask.

Save and upload the ini file, go to your EzPublish content edit interface, choose an image (the 'back' one you made earlier) choose the mypicturewitharoundedborder alias from the dropdown and publish. When you are happy that it's working delete the 'front' image and replace it with one that does something useful!

Thanks to Bruce Morrison from DesignIT for his invaluable help in wrangling ImageMagick's sometimes slightly-less-than-intuitive command line syntax.

Paul Bolger

Softriva .com

Tuesday 06 March 2007 6:03:38 am

Paul,

you mentioned picmask.png. Is this the same as front.png?

Can anyone tell me how can I get to eZ publish content edit interface?

paul bolger

Tuesday 06 March 2007 3:21:17 pm

"picmask.png" is just the name I happened to give the matt image - you can call it anything, as long as you put the correct name in the filter definition.

I don't understand your second question. Generally it's better to start a new thread if you want to address a different topic. You have more chance people will find it, and it's better for people browsing the forums in the future.

Paul Bolger

Bruce Morrison

Tuesday 03 July 2007 4:47:13 pm

Here's a javascript method

corner.js 1.3 allows you to add corners (and also shading and shadow) to images on your webpages (alternatively: glossy.js). It uses unobtrusive javascript to keep your code clean.

It works in all the major browsers - Mozilla Firefox 1.5+, Opera 9+, IE 6+ and Safari. On older browsers, it'll degrade and your visitors won't notice a thing.

http://www.netzgesta.de/corner/

Cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Pascal Specht

Wednesday 04 July 2007 12:00:20 am

I would be careful before going for the rounded corners from http://www.netzgesta.de/corner/ mentionned above...

My A/V scanner immediately raises a warning when rendering their demo page: the supposed virus is EXP/HTML.VML.Gen - maybe not that much "unobtrusive" javascript used there...

-Pascal

Softriva .com

Wednesday 04 July 2007 3:22:24 am

hmmm, I really liked this js. Are we in danger? How to solve this issue? Does it affect Linux servers? Can someone elaborate further.

I tried googling this virus but could not get definitive answer.

Softriva .com

Friday 06 July 2007 11:26:28 am

I have contacted the developer about this virus issue and below is his answer.

Under certain circumstances with a heuristic search the exploit "EXP/
HTML.VML.Gen" will falsely be discovered in "Corner.js" only. I would
fix it if the circumstances would be known.

The initialization of the VML support ...

document.namespaces.add("v", "urn:schemas-microsoft-com:vml");

... seems to release the virus warning!

Pascal Specht

Monday 09 July 2007 1:16:57 am

Concerning the A/V warning: I do not think that there's any danger in using the script: This is a false positive kind of warning. But the point is that the average visitor will just believe there's a potential risk if he/she gets this kind of warning, and would turn away...
If this is of any help: The problem has been reported by Avira, Sunbelt, and Panda, to name a few.

http://www.microsoft.com/technet/security/Bulletin/MS06-055.mspx

-Pascal

scrieler _

Wednesday 25 June 2008 3:20:20 am

heya, I test it, but I get a errorlog after using Filters[]=roundedborder=-compose dst-over -composite -gravity NorthWest ...../design/wvw_site/images/picmask.png

/usr/bin/convert: Unrecognized option (-compose).

I am using eZ 4.0 ezwebin and ImageMagick 6.2

Steven E. Bailey

Wednesday 25 June 2008 5:23:28 am

Your version of Imagemagick is too old.

Certified eZPublish developer
http://ez.no/certification/verify/396111

Available for ezpublish troubleshooting, hosting and custom extension development: http://www.leidentech.com

scrieler _

Wednesday 25 June 2008 11:33:23 pm

ok, I got it, thanks.

Now, I want to have rounded corners without overlay picture because I don't want to crop the picture. How can I use this -> http://valokuva.org/?p=45 ?

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.