Jump to content

saving png image to server properly


Nicholas Reed

Recommended Posts

I have just recompiled php with --enable-gd-jis-conv and --enable-mbstring and it works! I can't believe it.

 

I've figured out how to save Japanese text as a png image to the server and just was hoping a master could look over my png image saving code and tell me if I was going about it the right way or was going to cause a memory leak.. This code does successfully save the image to the server.

 

The code,

 

    public function makeJapaneseCharacter($font="static/JFONT2.TTF", $W=400, $H=100, $X=0, $Y=0, $fsize=18, $color=array(0x0,0x0,0x0), $bgcolor=array(0xFF,0xFF,0xFF))
    {
        $this->im = @imagecreate($W, $H)
            or die("Cannot Initialize new GD image stream");
            
        $background_color = imagecolorallocate($this->im, $bgcolor[0], $bgcolor[1], $bgcolor[2]);        //RGB color background.
        $text_color = imagecolorallocate($this->im, $color[0], $color[1], $color[2]);            //RGB color text.
                
        imagettftext($this->im, 58, 0, 50, 100, $text_color, $font, mb_convert_encoding('蠱惑', 'UTF8', 'UTF-8'));

        
        $this->saveAsPng("god", "static/"); //saves as god.png in the "static folder"
    }
    
    /**
     * @name saveAsPng
     */ 
    public function saveAsPng($fileName, $location= null){        
        
        $_fileName = $fileName.".png";
        $_fileName = is_null($location)?$_fileName:$location.$_fileName;
        return imagepng($this->im, $_fileName);        
    }     

 

 

Many thanks in advance.

 

Nicholas.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/243934-saving-png-image-to-server-properly/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.