Calculate image size in percentage in php -


i have piece of code adds watermark bottom right corner of uploaded photo. however, watermark doesen't change size according uploaded photo want do. i'd scale calculated on percentage, watermark 10% of uploaded photo , placed in bottom right corner. how can done?

this code:

// load stamp , photo apply watermark $stamp = imagecreatefromgif('../images/watermark.gif');  $marge_right = 5; $marge_bottom = 5; $sx = imagesx($stamp); $sy = imagesy($stamp);  $im = imagecreatefromjpeg($file_tmp) imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right,  imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 30); 

if have php 5.5+, this:

// load stamp , photo apply watermark $stamp = imagecreatefromgif('../images/watermark.gif'); $im = imagecreatefromjpeg($file_tmp);  $marge_right = 5; $marge_bottom = 5;  $percent = 10; $factor = 1 - ($percent/100);   $stampscaled = imagescale ($stamp, $factor * $imagesx($im));  $sx = imagesx($stampscaled); $sy = imagesy($stampscaled);  imagecopymerge($im, $stamp, imagesx($im) - $marge_right - $sx,  imagesy($im) - $marge_bottom - $sy, 0, 0, $factor * imagesx($im), $factor * imagesy($im), 30); 

note: work source images rectangular in size. extreme aspect ratios, might need use more sophisticated scaling.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -