/[drupal]/contributions/modules/textimage/textimage.module
ViewVC logotype

Diff of /contributions/modules/textimage/textimage.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.23.4.16, Wed May 20 00:02:29 2009 UTC revision 1.23.4.17, Tue Jun 2 22:27:46 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: textimage.module,v 1.23.4.15 2009/05/14 12:34:24 deciphered Exp $  // $Id: textimage.module,v 1.23.4.16 2009/05/20 00:02:29 deciphered Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 779  function textimage_text_to_image($text, Line 779  function textimage_text_to_image($text,
779    $fore = imagecolorallocatealpha($image, $r, $g, $b, $alpha);    $fore = imagecolorallocatealpha($image, $r, $g, $b, $alpha);
780    
781    imagettftext($image, $fontsize, $q_angle, $x, $y, $fore, $font, $text);    imagettftext($image, $fontsize, $q_angle, $x, $y, $fore, $font, $text);
782    if ($rotation !== 0) {    if ($rotation != 0) {
783      $image = imagerotate($image, $rotation, 0);      $image = imagerotate($image, $rotation, 0);
784    }    }
785    
# Line 789  function textimage_text_to_image($text, Line 789  function textimage_text_to_image($text,
789    return $image;    return $image;
790  }  }
791    
792    if (!function_exists('imagerotate')) {
793      function imagerotate($im, $angle, $bgcolor) {
794        if ($angle === 0) {
795          return $im;
796        }
797        // imagerotate() in php's libgd rotates the image counterclockwise,
798        // this implementation rotates clockwise. The angle needs to be
799        // inverted to give the same behaviour between these implementations.
800        $angle = 360 + $angle;
801    
802        $width  = imagesx($im);
803        $height = imagesy($im);
804        // background color.
805        list($r, $g, $b, $a) = _textimage_hex2rgb($bgcolor);
806    
807        switch ($angle) {
808          case 270:
809          case 90:
810            // flip dimensions.
811            $rot_width = $height;
812            $rot_height = $width;
813            break;
814          case 180:
815            // maintain dims.
816            $rot_width = $width;
817            $rot_height = $height;
818            break;
819        }
820    
821        $rotate = imagecreatetruecolor($rot_width, $rot_height);
822        $bg = imagecolorallocatealpha($rotate, $r, $g, $b, $a);
823        imagefilledrectangle($rotate, 0, 0, $rot_width, $rot_height, $bg);
824        imagealphablending($rotate, FALSE);
825        imagesavealpha($rotate, TRUE);
826    
827        switch ($angle) {
828          case 270:
829            $rot_width--;
830            for ($y = 0; $y < $height; ++$y)
831              for ($x = 0; $x < $width; ++$x)
832                imagesetpixel($rotate, $rot_width - $y, $x, imagecolorat($im, $x, $y));
833            break;
834          case 90:
835            $rot_height--;
836            for ($y = 0; $y < $height; ++$y)
837              for ($x = 0; $x < $width; ++$x)
838                imagesetpixel($rotate, $y, $rot_height - $x, imagecolorat($im, $x, $y));
839            break;
840          case 180:
841            $rot_width--;
842            $rot_height--;
843            for ($y = 0; $y < $height; ++$y)
844              for ($x = 0; $x < $width; ++$x)
845                imagesetpixel($rotate, $rot_width - $x, $rot_height - $y, imagecolorat($im, $x, $y));
846            break;
847        }
848        return $rotate;
849      }
850    }
851    
852  /**  /**
853   * load a preset by id or name.   * load a preset by id or name.
854   * @param preset   * @param preset

Legend:
Removed from v.1.23.4.16  
changed lines
  Added in v.1.23.4.17

  ViewVC Help
Powered by ViewVC 1.1.2