masking images

images php coding issues or problems here.

Moderators: macek, egami, gesf

gonzrona
New php-forum User
New php-forum User
Posts: 1
Joined: Sun Aug 21, 2011 8:21 am

masking images

Postby gonzrona » Sun Aug 21, 2011 10:30 am

I am making a site where users upload images for their profile. I already have that working just fine. However, I want the users images to be circles. From what I have read I believe that I can not crop an image into a circle, I will have to mask the image to make part of the image transparent. I have really no idea where to start. I would really appreciate it if anyone could point me in the right direction, or maybe even some sample code!!!

cnapsys
New php-forum User
New php-forum User
Posts: 2
Joined: Thu Sep 01, 2011 7:31 am

Re: masking images

Postby cnapsys » Thu Sep 01, 2011 7:34 am

depending on the color of your page background, the easiest solution I can think of would be to have a png mask that you can apply to your images just like a watermark.

c

lokanath7
New php-forum User
New php-forum User
Posts: 139
Joined: Mon Nov 15, 2010 12:11 am

Re: masking images

Postby lokanath7 » Fri Sep 02, 2011 3:16 am

try this....

Code: Select all

<?php
$img1 = imagecreateFromjpeg("image.jpg");
$x=imagesx($img1)-$width ;
$y=imagesy($img1)-$height;


$img2 = imagecreatetruecolor($x, $y);
$bg = imagecolorallocate($img2, 255, 255, 255);
imagefill($img2, 0, 0, $bg);

$e = imagecolorallocate($img2, 0, 0, 0);

$r = $x <= $y ? $x : $y;
imagefilledellipse($img2, ($x/2), ($y/2), $r, $r, $e);

imagecolortransparent($img2, $e);

imagecopymerge($img1, $img2, 0, 0, 0, 0, $x, $y, 100);

imagecolortransparent($img1, $bg);

header("Content-type: image/png");
imagepng($img1);

imagedestroy($img2);
imagedestroy($img1);


?>

mytony
New php-forum User
New php-forum User
Posts: 5
Joined: Wed Sep 14, 2011 6:19 pm

Re: masking images

Postby mytony » Wed Sep 14, 2011 6:39 pm

a little difficult for me.


Return to “PHP coding => Images”

Who is online

Users browsing this forum: No registered users and 1 guest

cron