PHP Thumb » Plugins » Plugin Showcase (Unofficial Plugins)

Rounded Corners plugin (no transparent)

(3 posts)
  1. leandono
    Member

    [Alpha Version]
    This plugin create rounded corners. Based on:

    Apply Rounded Corners to Images On-The-Fly Using PHP and GD Library


    The code generates a mask for the top-right corner by drawing a transparent circle over colored background. This mask is then rotated and superimposed on the specified image four times.

    Posted 8 months ago #
  2. leandono
    Member

    gd_rounded.inc.php

    Code:


    <?php
    //Based on http://911-need-code-help.blogspot.com/2009/05/generate-images-with-round-corners-on.html
    //(Comments in spanish, sorry!)

    class GdRoundedLib

    {
    /**
    * Instance of GdThumb passed to this class
    *
    * @var GdThumb
    */
    protected $parentInstance;
    protected $currentDimensions;
    protected $workingImage;
    protected $newImage;
    protected $options;
    public

    function createRounded($color_rounded = 'FFFFFF', $radio_rounded = 10, &$that)
    {

    // bring stuff from the parent class into this class...

    $this->parentInstance = $that;
    $this->currentDimensions = $this->parentInstance->getCurrentDimensions();
    $this->workingImage = $this->parentInstance->getWorkingImage();

    // Parametros

    $this->color_rounded = $color_rounded;
    $this->radio_rounded = $radio_rounded;
    $canvas_width = $this->currentDimensions['width'];
    $canvas_height = $this->currentDimensions['height'];

    // Crea una imagen de forma cuadrada

    $corner_image = imagecreatetruecolor($this->radio_rounded, $this->radio_rounded);

    // Pinta la figura de negro

    $clear_colour = imagecolorallocate($corner_image, 0, 0, 0);

    // La pinta del color que seleccionamos

    $solid_colour = imagecolorallocate($corner_image, hexdec(substr($this->color_rounded, 0, 2)) , hexdec(substr($this->color_rounded, 2, 2)) , hexdec(substr($this->color_rounded, 4, 2)));

    // Crea la transparencia

    imagecolortransparent($corner_image, $clear_colour);
    imagefill($corner_image, 0, 0, $solid_colour);

    // Crea un eclipse

    imagefilledellipse($corner_image, $this->radio_rounded, $this->radio_rounded, $this->radio_rounded * 2, $this->radio_rounded * 2, $clear_colour);

    // Copia y une la imagen

    imagecopymerge($this->workingImage, $corner_image, 0, 0, 0, 0, $this->radio_rounded, $this->radio_rounded, 100);

    // La da vuelta

    $corner_image = imagerotate($corner_image, 90, 0);

    // Copia y une la imagen

    imagecopymerge($this->workingImage, $corner_image, 0, $canvas_height - $this->radio_rounded, 0, 0, $this->radio_rounded, $this->radio_rounded, 100);

    // La da vuelta

    $corner_image = imagerotate($corner_image, 90, 0);

    // Copia y une la imagen

    imagecopymerge($this->workingImage, $corner_image, $canvas_width - $this->radio_rounded, $canvas_height - $this->radio_rounded, 0, 0, $this->radio_rounded, $this->radio_rounded, 100);

    // La da vuelta

    $corner_image = imagerotate($corner_image, 90, 0);

    // Copia y une la imagen

    imagecopymerge($this->workingImage, $corner_image, $canvas_width - $this->radio_rounded, 0, 0, 0, $this->radio_rounded, $this->radio_rounded, 100);

    imagedestroy( $corner_image );

    // Devuelve la imagen

    return $that;
    }
    }

    $pt = PhpThumb::getInstance();
    $pt->registerPlugin('GdRoundedLib', 'gd');
    ?>

    End of code

    Example:


    <?php

    require_once '../ThumbLib.inc.php';

    $color_rounded = 'E84E00';
    $radio_rounded = 40;

    $thumb = PhpThumbFactory::create('test.jpg');
    $thumb->adaptiveResize(300, 300)->createRounded($color_rounded, $radio_rounded);
    $thumb->show();

    ?>

    Posted 8 months ago #
  3. Nice one, if you'd like it included in the distribution, why not fork the project on github, add your code, and send me a pull request (http://github.com/iselby/PHPThumb)? That way you can keep original credit for the code, etc.

    Otherwise, great work, people can grab it from here!

    Posted 8 months ago #

RSS feed for this topic

Reply

You must log in to post.