I needed to round just the top corners of an image and leave the bottoms square for a project so I wrote a patch that allows each corner on an image to be rounded at any radius. Previously you could only set one radius that would be used on all corners.

Please review this patch and get back to me with comments and suggestions.

Members fund testing for the Drupal project. Drupal Association Learn more


dman’s picture

Thanks for this. It makes sense. I knew this was going to be a request eventually. Thanks for looking at it for us.
Visually the code looks fine. I'd like to roll it up a little more to avoid repetition, but the approach is just right.
Glad you figured out how to use the 'mask' shape bulder :-}

I'll give it a full review and roll it in soon.

dman’s picture

Patch applied clean.
I got some PHP complaints about undefined variables (normal).
Tweaked it to expand the UI if selected.
It certainly does the job.
Thanks for the logic on filling in the blocks there. I think I get it. SHould work as long as nobody tries to make radiuses larger than half the image.
... next thing we know, someone will want ellipse corners ;-)

I trimmed down the UI cut & paste a bit, eg I renamed the individual '$radiustl' sorta variables into a real array, and worked with the array directly, producing code more like :

  $corners = array(
    'tl' => t("Top Left Radius"),
    'tr' => t("Top Right Radius"),
    'bl' => t("Bottom Left Radius"),
    'br' => t("Bottom Right Radius"),
  // Loop over the four corners and create field elements for them.
  $form['independent_corners_set']['radii'] = array('#type' => 'item');
  foreach ($corners as $attribute => $label) {
    $form['independent_corners_set']['radii'][$attribute] = array(
        '#type' => 'textfield',
        '#title' => $label,
        '#default_value' => 0+$action['independent_corners_set']['radii'][$attribute],
        '#size' => 2,

... it's more elegant in some places. Not much advantage in others (possibly actually less readable), but I tend to fold repeated text up into loops where I can.

  * Implementation of theme_hook() for imagecache_ui.module
 function theme_canvasactions_roundedcorners($element) {
   $data = $element['#value'];
    $dimens = join('px | ', $data['independent_corners_set']['radii']).'px';
  } else { 
    $dimens = "Radius: {$data['radius']}px "; 
  return $dimens . ($data['antialias'] ? "antialiased" : "") ;

(I also added some UI tweaks to alert prople to the limitations of imagemagick - this is a different issue, but I rolled it today anyway.)

all in DRUPAL-6--1 DEV.
Not a release yet. Needs testing I guess. I wish a test suite were possible for images :-}

mason@thecodingdesigner.com’s picture

Thanks for the feedback and I like the code reformatting. It's definitely cleaner to treat the corners as an array. I'll use this version in my project and report back any issues. I'll also try to have some others take a look at it.

Two quick things:
I can only dl this version thru cvs. The dev snapshot on the project page is still the older version.
And you didn't include the imagecache_actions.jquery.js file in your commit.

dman’s picture

CVS not getting bundled is sorta normal. The changes roll overnight or over some hours or something. The date now says Mar 15, so I'm thinking it's ready.

What is imagecache_actions.jquery.js ? It didn't come with your patch either, although I saw it mentioned. ;-)

dman’s picture

Note, I found some issues where my changes to the maths had incorrectly re-used the $radius variable as a counter, not a default. My logic bad.
Fixing in dev now. CVS tarball may take a while. Continue to use CVS direct to checkout for now.

mason@thecodingdesigner.com’s picture

Ahh, got it. I didn't know about how the tarballs were made. I'm new to cvs.

I'm attaching the .js file. It's not much, but it disables the appropriate input fields when you check and uncheck the 'independent radius' checkbox.

dman’s picture

It's pretty small stuff, but it certainly got the 'unobtrusive' bit working because I never noticed it missing.

I've reviewed it, and added a shorter modified version that gets jquery to do the hard work for us:
"#independent-corners-set-wrapper .form-text"

function canvasactions_roundedcorners_form_disable_fields(){
  // canvasactions_roundedcorners
  // check if independent corners are enabled and disable other fields
    $("#independent-corners-set-wrapper .form-text").attr("disabled", true).addClass("disabled");
    $(":input#edit-data-radius").attr("disabled", false).removeClass("disabled");
  } else {
    $(":input#edit-data-radius").attr("disabled", true).addClass("disabled");
    $("#independent-corners-set-wrapper .form-text").attr("disabled", false).removeClass("disabled");

:-B I always vaporize repetition when I see it!

mason@thecodingdesigner.com’s picture

Sweet. Die, repetition, die!
Die, repetition.

dman’s picture

Status: Needs review » Fixed

http://drupal.org/node/413948 committed to current version

mason@thecodingdesigner.com’s picture

Sweet, thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.