php - Center image inside image using imagecopy function -


i have simple script adds image inside image. here code:

<?php  $im = imagecreatetruecolor(650, 400); $stamp = imagecreatefrompng('test.png');  $red = imagecolorallocate($im, 209, 231, 244); imagefill($im, 0, 0, $red);  $marge_right = 10; $marge_bottom = 133; $sx = imagesx($stamp); $sy = imagesy($stamp);  imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im)  - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));  header('content-type: image/png'); imagepng($im); imagedestroy($im);   ?> 

now place test image 10x right of big image , 133px bottom of image. how place image centered vertically depending on height??

thanks

$marge_right , $marge_bottom should correspond difference of horizontal , vertical sizes (respectively) between source , destination images.

so need calculate difference way:

$marge_right = abs($dest_sx-$src_sx); $marge_bottom = abs($dest_sy-$src_sy); 

the abs optional if sure source bigger source smaller destination.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -