/[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.19.2.18, Wed May 20 00:03:48 2009 UTC revision 1.19.2.19, Tue Jun 2 22:28:51 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: textimage.module,v 1.19.2.17 2009/05/14 12:36:47 deciphered Exp $  // $Id: textimage.module,v 1.19.2.18 2009/05/20 00:03:48 deciphered Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 752  function textimage_text_to_image($text, Line 752  function textimage_text_to_image($text,
752    $fore = imagecolorallocatealpha($image, $r, $g, $b, $alpha);    $fore = imagecolorallocatealpha($image, $r, $g, $b, $alpha);
753    
754    imagettftext($image, $fontsize, $q_angle, $x, $y, $fore, $font, $text);    imagettftext($image, $fontsize, $q_angle, $x, $y, $fore, $font, $text);
755    if ($rotation !== 0) {    if ($rotation != 0) {
756      $image = imagerotate($image, $rotation, 0);      $image = imagerotate($image, $rotation, 0);
757    }    }
758    
# Line 762  function textimage_text_to_image($text, Line 762  function textimage_text_to_image($text,
762    return $image;    return $image;
763  }  }
764    
765    if (!function_exists('imagerotate')) {
766      function imagerotate($im, $angle, $bgcolor) {
767        if ($angle === 0) {
768          return $im;
769        }
770        // imagerotate() in php's libgd rotates the image counterclockwise,
771        // this implementation rotates clockwise. The angle needs to be
772        // inverted to give the same behaviour between these implementations.
773        $angle = 360 + $angle;
774    
775        $width  = imagesx($im);
776        $height = imagesy($im);
777        // background color.
778        list($r, $g, $b, $a) = _textimage_hex2rgb($bgcolor);
779    
780        switch ($angle) {
781          case 270:
782          case 90:
783            // flip dimensions.
784            $rot_width = $height;
785            $rot_height = $width;
786            break;
787          case 180:
788            // maintain dims.
789            $rot_width = $width;
790            $rot_height = $height;
791            break;
792        }
793    
794        $rotate = imagecreatetruecolor($rot_width, $rot_height);
795        $bg = imagecolorallocatealpha($rotate, $r, $g, $b, $a);
796        imagefilledrectangle($rotate, 0, 0, $rot_width, $rot_height, $bg);
797        imagealphablending($rotate, FALSE);
798        imagesavealpha($rotate, TRUE);
799    
800        switch ($angle) {
801          case 270:
802            $rot_width--;
803            for ($y = 0; $y < $height; ++$y)
804              for ($x = 0; $x < $width; ++$x)
805                imagesetpixel($rotate, $rot_width - $y, $x, imagecolorat($im, $x, $y));
806            break;
807          case 90:
808            $rot_height--;
809            for ($y = 0; $y < $height; ++$y)
810              for ($x = 0; $x < $width; ++$x)
811                imagesetpixel($rotate, $y, $rot_height - $x, imagecolorat($im, $x, $y));
812            break;
813          case 180:
814            $rot_width--;
815            $rot_height--;
816            for ($y = 0; $y < $height; ++$y)
817              for ($x = 0; $x < $width; ++$x)
818                imagesetpixel($rotate, $rot_width - $x, $rot_height - $y, imagecolorat($im, $x, $y));
819            break;
820        }
821        return $rotate;
822      }
823    }
824    
825  /**  /**
826   * load a preset by id or name.   * load a preset by id or name.
827   * @param preset   * @param preset

Legend:
Removed from v.1.19.2.18  
changed lines
  Added in v.1.19.2.19

  ViewVC Help
Powered by ViewVC 1.1.2