Imagestring对齐右侧

时间:2013-09-01 00:36:28

标签: php string image

我想将图像的水印与右侧对齐。

这是我到目前为止所做的,但它与左边对齐......

// 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;

1 个答案:

答案 0 :(得分:0)

替换

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

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