2016-12-15 100 views
0

所以我的下面的代码工作就像如果我上传图像它将调整图像大小为720x450然后水印它。但我不希望修改宽度和高度,并将水印放在任何尺寸的图像的右下角水印上传图像没有调整大小图像宽度高度

如果有人可以帮我在这里?

$image_path = "../images/watermark.png"; 
function watermark_image($oldimage_name, $new_image_name){ 
    global $image_path; 
    list($owidth,$oheight) = getimagesize($oldimage_name); 
    $width = 720; $height = 450;  
    $im = imagecreatetruecolor($width, $height); 
    $img_src = imagecreatefromjpeg($oldimage_name); 
    imagecopyresampled($im, $img_src, 0, 0, 0, 0, $width, $height, $owidth, $oheight); 
    $watermark = imagecreatefrompng($image_path); 
    list($w_width, $w_height) = getimagesize($image_path);   
    $pos_x = $width - $w_width; 
    $pos_y = $height - $w_height; 
    imagecopy($im, $watermark, $pos_x, $pos_y, 0, 0, $w_width, $w_height); 
    imagejpeg($im, $new_image_name, 90); 
    imagedestroy($im); 
    unlink($oldimage_name); 
    return true; 
} 

感谢您的帮助和时间。

回答

1

您提供手动高度和宽度,只需指定图像

$image_path = "../images/watermark.png"; 
function watermark_image($oldimage_name, $new_image_name){ 
    global $image_path; 
    list($owidth,$oheight) = getimagesize($oldimage_name); 
    $width = $owidth; $height = $oheight;  
    $im = imagecreatetruecolor($width, $height); 
    $img_src = imagecreatefromjpeg($oldimage_name); 
    imagecopyresampled($im, $img_src, 0, 0, 0, 0, $width, $height, $owidth, $oheight); 
    $watermark = imagecreatefrompng($image_path); 
    list($w_width, $w_height) = getimagesize($image_path);   
    $pos_x = $width - $w_width; 
    $pos_y = $height - $w_height; 
    imagecopy($im, $watermark, $pos_x, $pos_y, 0, 0, $w_width, $w_height); 
    imagejpeg($im, $new_image_name, 90); 
    imagedestroy($im); 
    unlink($oldimage_name); 
    return true; 
} 

的原始高度ANS宽度试试这个,你会正常运行。

更多信息点击这里http://php.net/manual/en/image.examples-watermark.php

+0

欣赏队友,但水印我需要它,在它做它在顶部的左下角 –

+0

根据您的需要@johrampong设置$ POS_X和$ POS_Y值。它将工作 –

+0

仍然在左上角队友 –

相关问题