Sign up to create your own snipts, or login.

Public snipts » image generation The latest public image generation snipts.

showing 1-1 of 1 snipts for image generation
  • Symfony - Action for text image generation (using GD)
    <?php
      public function executeGenerateText (sfWebRequest $request) {
        $font = '/images/ROTISSAS.TTF';
        $bbox = imageftbbox(20, 0, $font, $this->getRequestParameter('text') );
        
        $width = $bbox[2] - $bbox[0] + 10;
        $height = $bbox[1] - $bbox[7] + 10;
        
        $im = imagecreatetruecolor($width, $height);
        $black = imagecolorallocate($im, 0, 0, 0);
        $white = imagecolorallocate($im, 255, 255, 255);
        
        // Set the background to be white
        // Path to our font file
        // First we create our bounding box
        
        
        imagefilledrectangle($im, 0, 0, $width, $height, $black);
    
        // This is our cordinates for X and Y
        $x = $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2);
        //$y = $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) + 3 ;
        $y = 28;
        
        imagefttext($im, 20, 0, 0, $y, $white, $font, $this->getRequestParameter('text'));
        
        // Output to browser
        header('Content-type: image/png');
        
        imagepng($im);
        imagedestroy($im);
    
        return sfView::NONE;
      }//executeGenerateText
    ?>
    
    
    # USAGE
    
    <img src="<? echo url_for('modulename/generateText?text=My text'); ?>" alt="" title="" />
    

    copy | embed

    0 comments - tagged in  posted by Tram on Jan 15, 2009 at 10:11 a.m. EST
Sign up to create your own snipts, or login.