2013-09-01 113 views
0

我想要將圖像的水印對齊到右側。Imagestring向右對齊

這是我迄今爲止,但其左對齊......

// Add Watermark featuring Website Name 
$home_url = home_url(); 
$search = array('http://','https://'); 
$site_name = str_ireplace($search, '', $home_url); 
$watermark = imagecreatetruecolor($width, $height+15); 

// Determine color of watermark's background 
if (is_array($Meme_Generator_Data) && 
    array_key_exists('watermark_background',$Meme_Generator_Data) && 
    strlen($Meme_Generator_Data['watermark_background']) == 7) 
{ 
    $wm_bg = $this->convert_color(substr($Meme_Generator_Data['watermark_background'], 1)); 
    $bg_color = imagecolorallocate($watermark, $wm_bg[0], $wm_bg[1], $wm_bg[2]); 
    imagefill($watermark, 0, 0, $bg_color); 
} 

// Determine color of watermark's text 
if (is_array($Meme_Generator_Data) && 
    array_key_exists('watermark_text',$Meme_Generator_Data) && 
    strlen($Meme_Generator_Data['watermark_text']) == 7) 
{ 
    $wm_text = $this->convert_color(substr($Meme_Generator_Data['watermark_text'], 1)); 
    $text_color = imagecolorallocate($watermark, $wm_text[0], $wm_text[1], $wm_text[2]); 
} else { 
    $text_color = imagecolorallocate($watermark, 255, 255, 255); 
} 

imagestring($watermark, 5, 5, $height, $site_name, $text_color);      
imagecopy($watermark, $img, 0, 0, 0, 0, $width, $height); 
$img = $watermark; 

回答

0

更換

imagecopy($watermark, $img, 0, 0, 0, 0, $width, $height); 

imagecopy($watermark, $img, imagesx($img) - $width, 0, 0, 0, $width, $height);