Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.