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

Legend:
Removed from v.1.39  
changed lines
  Added in v.1.40

  ViewVC Help
Powered by ViewVC 1.1.2