php ile resim köşelerini yuvarlayan class
PHP ile resimlerin köşelerini bu ufak class yardımı ile yuvarlayabiliriz.
<?php /* * Created on 15.Ara.2006 * * A simple class that creates rounded corner images for tables * Coded By Ozgur Kaya * <a href="mailto:ozgurkaya01@hotmail.com">ozgurkaya01@hotmail.com</a> */ class roundedCorners { var $width = 50; var $height = 50; var $bgcolor = "#FFFFFF"; var $imagecolor = "#ff0000"; var $align; var $cx; var $cy; var $image; var $type = "jpeg"; var $transparent = false; function roundedCorners($width,$height,$align,$bgcolor,$color,$type,$transparent){ $this->setWidth($width); // sets image width $this->setHeight($height); // sets image height $this->setAlign($align); // sets align of image (top-left, top-right, bottom-left, bottom-right) $this->setbgColor($bgcolor); // set image background color $this->setImageColor($color); // set rounded image color $this->setType($type); // set extension for image (jpg,gif,png) $this->setTransparent($transparent); // set transparency of the image } function setAlign($align){ $align = ($align) ? $align : $this->align; if ($this->width == $this->height) { $align_array = array ( "tl"=>array($this->width,$this->height), "tr"=>array(0,$this->width), "bl"=>array($this->height,0), "br"=>array(0,0) ); } elseif ($this->width > $this->height) { $align_array = array ( "tl"=>array($this->width,$this->height), "tr"=>array(0,$this->height), "bl"=>array($this->height*2,0), "br"=>array(0,0) ); } elseif ($this->width < $this->height) { $align_array = array ( "tl"=>array($this->width,$this->height), "tr"=>array(0,$this->height), "bl"=>array($this->width,0), "br"=>array(0,0) ); } $this->cx = $align_array[$align][0]; $this->cy = $align_array[$align][1]; } function setWidth($width){ $this->width = ($width) ? $width : $this->width; } function setHeight($height) { $this->height = ($height) ? $height : $this->height; } function setBgColor($bgcolor){ $this->bgcolor = ($bgcolor) ? $bgcolor : $this->bgcolor; } function setImageColor($color) { $this->imagecolor = ($color) ? $color : $this->imagecolor; } function setType($type){ if ($type == "jpg") $type = "jpeg"; $types = array("gif","jpeg","png"); $type = (in_array($type,$types)) ? $type : "jpeg"; $this->type = $type; } function setTransparent($transparent){ if ($transparent) { $this->type = "gif"; $this->transparent = true; } else $this->transparent = false; } function displayImage($type){ $types = array ("gif"=>"gif","png"=>"png","jpg"=>"jpeg"); $type = $types[$type]; header("Content-type: image/png]}"); imagepng($this->image); } function createRGBValues($color) { $color = str_replace("#","",$color); $rgb["red"] = hexdec(substr($color,0,2)); $rgb["green"] = hexdec(substr($color,2,2)); $rgb["blue"] = hexdec(substr($color,4,2)); return $rgb; } function createImage() { $this->image = imagecreatetruecolor($this->width,$this->height); // $bg_rgb = $this->createRGBValues($this->bgcolor); $bg = imagecolorallocate($this->image, $bg_rgb["red"], $bg_rgb["green"], $bg_rgb["blue"]); if ($this->transparent) $bg = imagecolortransparent($this->image,$bg); imagefill($this->image, 0, 0, $bg); // $img_rgb = $this->createRGBValues($this->imagecolor);; $col_ellipse = imagecolorallocate($this->image, $img_rgb["red"], $img_rgb["green"], $img_rgb["blue"]); $w = $this->width * 2; $h = $this->height * 2; imagefilledellipse($this->image, $this->cx, $this->cy, $w, $h, $col_ellipse); header("Content-type: image/{$this->type}"); // set header (you can use different types png,jpeg,gif switch ($this->type){ case "gif": imagegif($this->image); break; case "png": imagepng($this->image); break; case "jpeg": imagejpeg($this->image); break; } } } ?>
Kullanımı
<?php //using class $img = new roundedCorners($_GET['w'],$_GET['h'],$_GET['al'],$_GET['bg'],$_GET['cl'],$_GET['type'],$_GET['tr']); // create a new rounded corner image object with width, height, and align attributes $img->createImage(); // create image // ?>