eZ Community » Forums » Setup & design » Images with round corners
expandshrink

Images with round corners

Images with round corners

Sunday 23 August 2009 5:48:36 pm - 7 replies

Hi

Anyone knows how to make round corners with image magick and using the built in image handling system in eZ?

I have read in the forum about some solutions using one large mask and then composing this with your image. Problem is that I don't know the exact size of the image so we need to use one image/mask for each corner.

With plain image magick it would be something like 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

Now the questions is how to merge this with how eZ handles images.

Any ideas?

Fredrik

Sunday 23 August 2009 7:19:52 pm

I found this related article on eZpedia

http://ezpedia.org/en/snippet/tem...ide_rounded_corners_on_image_aliases

Cheers,
Heath

Monday 24 August 2009 5:00:45 am

Hi Heath

Thanks for the swift answer.

This is actually the same article i started with. This approach is fairly straight forward and after some tweaking I manged to get this to work.

The main disadvantage is that the mask and the image needs to be exactly the same size. Meaning that you need to work with fixed size images. This is ok for some of our project but many projects have a fixed image width but a flexible height. All dependent on the original image ratio.

So what I need is an approach where 4 corner images/masks are composed on the image creating the mask.

Any ideas?

Fredrik

Monday 24 August 2009 6:08:08 am

Fredrik,

Your welcome. If I can share I try to do it quickly so If I can't help I can do the next best thing, get out of the way.

In truth I just don't have time to go find the example I remember using before. I used to do so much custom image magic in years past, with all my examples dust to the wind.

I had hoped the article helps get some started. I hope it guides them along the path towards the next more complicated example. If you find one, do you mind adding a link in the article?

Best wishes. *steps to the side*

Cheers,
Heath

Monday 24 August 2009 6:20:15 am

<i>http://stackoverflow.com/question...corners-of-pictures-with-imagemagick
http://ez.no/developer/forum/setup_design/rounded_corners_on_images
http://ajaxian.com/archives/googles-rounded-corner-generator
http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=8401
</i>

Tuesday 25 August 2009 3:37:11 am

Thanks for the great input..

As I see it the ImageMagick command needs to be executed in one command in order to run with in eZ? Also it has to be done without creating any temporary files or masks since these will be hard to clean up?

Anyone figured out how to add 4 separate corners in an image together with convert in one command? Then how to translate this into a filter for image.ini?

Fredrik

Friday 20 November 2009 2:20:41 pm

One solution is to use PostParameters to round the corners of *ALL* images. This is because the PostParameters setting isn't escaped onto the command line, as are the Filters. I couldn't get the ImageMagick command line options used for rounding to pass properly through the escaping using Filters.

Formats that don't support transparency don't display the rounded corners, thus, .jpgs are unchanged, unless you choose to use one of the 'rounded' aliases.

ez/settings/override/image.ini.append.php

<?php /* #?ini charset="utf-8"?

[AliasSettings]
AliasList[]=rounded-small
AliasList[]=rounded-medium
AliasList[]=rounded-large

[rounded-small]
MIMEType=image/png
Reference=small

[rounded-medium]
MIMEType=image/png
Reference=medium

[rounded-large]
MIMEType=image/png
Reference=large

[ImageMagick]
IsEnabled=true
ExecutablePath=/usr/local/bin
Executable=convert
ExecutableUnix=convert

# This line causes ALL images to have their corners rounded. Only .gifs and .pngs will display with rounded corners, .jpgs
# will display with sharp corners, because they don't support transparency. If a .jpg image is uploaded, the display class
# must be set to one of the above for the rounded corner version to display.
#
# The PostParameters settings must also be applied before the destination file name, modify /var/www/html/ez/lib/ezimage/classes/ezimageshellhandler.php
#
# Thanks to: http://www.imagemagick.org/Usage/thumbnails/#rounded
PostParameters=\( +clone -threshold -1 -draw "fill black polygon 0,0 0,10 10,0 fill white circle 10,10 10,0" \( +clone -flip \) -compose Multiply -composite \( +clone -flop \) -compose Multiply -composite \) +matte -compose CopyOpacity -composite

*/ ?>

I modified /var/www/html/ez/lib/ezimage/classes/ezimageshellhandler.php to place the Filters and PostParameters between the source and destination filenames, because this is how I usually work with ImageMagick.

/var/www/html/ez/lib/ezimage/classes/ezimageshellhandler.php

if ( $filters !== false )
{
foreach ( $filters as $filterData )
{
$argumentList[] = $this->textForFilter( $filterData );
}
}

/* Move PostParameters up before the destination file is named */
if ( $this->PostParameters )
$argumentList[] = $this->PostParameters;

$destinationURL = $destinationMimeData['url'];

Finally, although I tried to use the debug settings to output the commandline, I didn't have any luck. To support development, I added the following line to the same file:

file_put_contents('/tmp/eZ.out',$systemString."\n",FILE_APPEND);

/* Added just before the execution */
system( $systemString, $returnCode );[/

Modified on Friday 20 November 2009 2:30:06 pm by Betsy Gamrat

Tuesday 22 November 2011 9:32:48 pm

One solution is to use PostParameters to round the corners of *ALL* images. This is because the PostParameters setting isn't escaped onto the command line, as are the Filters. I couldn't get the ImageMagick command line options used for rounding to pass properly through the escaping using Filters.

Formats that don't support transparency don't display the rounded corners, thus, .jpgs are unchanged, unless you choose to use one of the 'rounded' aliases.

...

# Thanks to: http://www.imagemagick.org/Usage/thumbnails/#rounded
PostParameters=\( +clone -threshold -1 -draw "fill black polygon 0,0 0,10 10,0 fill white circle 10,10 10,0" \( +clone -flip \) -compose Multiply -composite \( +clone -flop \) -compose Multiply -composite \) +matte -compose CopyOpacity -composite

...

By experimentation, I found that the commands at the link you mentioned (http://www.imagemagick.org/Usage/thumbnails/#rounded) can work in the filter system in image.ini.append.php if you simply remove the backslashes in front of the parentheses.  In this way, you can achieve what you want for the image alias you want, instead of applying this to all images.

The details are on my blog at http://share.ez.no/blogs/a-fowler/rounded-corners-for-user-avatars.

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from