note 42243 added to function.imagecopymerge
| From: | claudio dot gaetani at gdldesign dot it | Date: | Sun, 09 May 2004 15:04:00 +0000 |
| Subject: | note 42243 added to function.imagecopymerge | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-69375@lists.php.net to get a copy of this message | ||
This function is intended to serve as an example for the
"imageCopyMerge"-"ImageCopyResized", "ImageColorTransparent"
functions.
I hope it will help.
This function pick an image, square cut it resampled at the size requested and finishing merge the
result with another one to obtain a circular image result. I have a problem to obtain an thumbnail
that respect the colors and at the same time where cutted in a circular form, I hope this solution
can gives you a clue to obtain a free form images, I use this one also to create multicutted images.
<?php
$generalsrc="$image"; //the image to resample, resize and iconaize
$final_thumbwidth ="125";
$final_thumbheight ="125";
$abc = imagecreatefromjpeg("$generalsrc");
$def = imagecreatetruecolor($final_thumbwidth, $final_thumbheight);
$src_mx = round((imagesx($abc) / 2)-"0.1"); // middle x point of the image
$src_my = round((imagesy($abc) / 2)-"0.1"); // middle y point of the image
$src_x = ($src_mx * 2);
$src_y = ($src_my * 2);
$src_sq = ($src_x >= $src_y)?$src_y:$src_x; //used to define the best size for a square cut of
the image
$pl = ($src_x >= $src_y)?"1":"2"; //define if the image is portait or
landscape
$strt_pntx = ($pl=="1")?round(($src_my / 2)-"0. 1"):"0"; //defines
the x start point
$strt_pnty = ($pl=="2")?round(($src_mx / 2)-"0. 1"):"0"; //defines
the y start point
imagecopyresized($def, $abc, 0, 0, $strt_pntx, $strt_pnty, $final_thumbwidth, $final_thumbheight,
$src_sq, $src_sq);
$overlay_img = imagecreatefromPNG("circle_125.png"); //NOTE use png for this
$src_w = "ImageSX($overlay_img)";
$src_h = "ImageSY($overlay_img)";
$can_img = imagecreatetruecolor($src_w, $src_h);
$black = ImageColorAllocate ($overlay_img, 0, 0, 0);
ImageColorTransparent($overlay_img , $black);
imagecopy($can_img, $def, 0,0,0,0, $src_w, $src_h);
imagecopymerge($can_img, $overlay_img , 0,0,0,0, ImageSX($overlay_img), ImageSY($overlay_img),100);
//Imagecopy won't work, you must used imagecopymerge
ImageJPEG($can_img,"merge_$generalsrc",100);
imagedestroy($overlay_img);
imagedestroy($can_img);
ImageDestroy($abc);
ImageDestroy($def);
print "<HTML><HEAD><TITLE>test</TITLE></HEAD><BODY>
original:<hr><img src=\"$generalsrc\"
width=\"300\"><br><br><br>new:<hr><img
src=\"merge_$generalsrc\">
<br>width = $src_x
<br>height = $src_y
<br>mdlw = $src_mx
<br>mdlh = $src_my
<br>sqr = $src_sq
<br>pl = $pl
<br>start point x = $strt_pntx
<br>start point y = $strt_pnty
</BODY></HTML>";
?>
----
Manual Page -- http://www.php.net/manual/en/function.imagecopymerge.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42243
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42243&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42243&report=yes
Search -- http://master.php.net/manage/user-notes.php