Comments (3)
Davi, adaptei a função do link acima com a classe. Segue abaixo:
//$borda = caminho da imagem da borda
public function arredonda($borda, $radius = 20, $angle = 0, $topleft = true, $bottomleft = true, $bottomright = true, $topright = true) {
$corner_source = imagecreatefrompng($borda);
$corner_width = imagesx($corner_source);
$corner_height = imagesy($corner_source);
$corner_resized = ImageCreateTrueColor($radius, $radius);
ImageCopyResampled($corner_resized, $corner_source, 0, 0, 0, 0, $radius, $radius, $corner_width, $corner_height);
$corner_width = imagesx($corner_resized);
$corner_height = imagesy($corner_resized);
$this->img_temp = imagecreatetruecolor($corner_width, $corner_height);
$this->img_temp = $this->img;
$white = ImageColorAllocate($this->img_temp, 255, 255, 255);
$black = ImageColorAllocate($this->img_temp, 0, 0, 0);
// Top-left corner
if ($topleft == true) {
$dest_x = 0;
$dest_y = 0;
imagecolortransparent($corner_resized, $black);
imagecopymerge($this->img_temp, $corner_resized, $dest_x, $dest_y, 0, 0, $corner_width, $corner_height, 100);
}
// Bottom-left corner
if ($bottomleft == true) {
$dest_x = 0;
$dest_y = $this->altura - $corner_height;
$rotated = imagerotate($corner_resized, 90, 0);
imagecolortransparent($rotated, $black);
imagecopymerge($this->img_temp, $rotated, $dest_x, $dest_y, 0, 0, $corner_width, $corner_height, 100);
}
// Bottom-right corner
if ($bottomright == true) {
$dest_x = $this->largura - $corner_width;
$dest_y = $this->altura - $corner_height;
$rotated = imagerotate($corner_resized, 180, 0);
imagecolortransparent($rotated, $black);
imagecopymerge($this->img_temp, $rotated, $dest_x, $dest_y, 0, 0, $corner_width, $corner_height, 100);
}
// Top-right corner
if ($topright == true) {
$dest_x = $this->largura - $corner_width;
$dest_y = 0;
$rotated = imagerotate($corner_resized, 270, 0);
imagecolortransparent($rotated, $black);
imagecopymerge($this->img_temp, $rotated, $dest_x, $dest_y, 0, 0, $corner_width, $corner_height, 100);
}
// Rotate image
$this->img = imagerotate($this->img_temp, $angle, $white);
imagedestroy($corner_source);
return $this;
}
from canvas2.
Achei um script que deu um resultado melhor:
fonte: http://911-need-code-help.blogspot.com/2009/05/generate-images-with-round-corners-on.html
public function arredonda($radius = 10, $colour = "FFFFFF")
{
/* http://911-need-code-help.blogspot.com/2009/05/generate-images-with-round-corners-on.html
* radius: corner radius in pixels -- default value is 10
* colour: corner colour in rgb hex format -- default value is FFFFFF */
/* create mask for top-left corner in memory */
$corner_image = imagecreatetruecolor($radius, $radius);
$clear_colour = imagecolorallocate($corner_image, 0, 0, 0);
$solid_colour = imagecolorallocate($corner_image, hexdec(substr($colour, 0, 2)), hexdec(substr($colour, 2, 2)), hexdec(substr($colour, 4, 2)));
imagecolortransparent($corner_image, $clear_colour);
imagefill($corner_image, 0, 0, $solid_colour);
imagefilledellipse($corner_image, $radius, $radius, $radius * 2, $radius * 2, $clear_colour);
/* render the top-left, bottom-left, bottom-right, top-right corners by rotating and copying the mask */
$this->img_temp = $this->img;
imagecopymerge($this->img_temp, $corner_image, 0, 0, 0, 0, $radius, $radius, 100);
$corner_image = imagerotate($corner_image, 90, 0);
imagecopymerge($this->img_temp, $corner_image, 0, $this->altura - $radius, 0, 0, $radius, $radius, 100);
$corner_image = imagerotate($corner_image, 90, 0);
imagecopymerge($this->img_temp, $corner_image, $this->largura - $radius, $this->altura - $radius, 0, 0, $radius, $radius, 100);
$corner_image = imagerotate($corner_image, 90, 0);
imagecopymerge($this->img_temp, $corner_image, $this->largura - $radius, 0, 0, 0, $radius, $radius, 100);
/* output the image -- revise this step according to your needs */
$this->img = $this->img_temp;
return $this;
}
from canvas2.
Fala Edu, tem como escrever testes, padronizar o nome em inglês e fazer um pull request?
Valeu!
from canvas2.
Related Issues (7)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from canvas2.