treinetic/imageartist

ImageArtist 是一个 php gd 包装器,使图像处理变得极为简单,我们将 ImageArtist 介绍为 PHP 的 Photoshop

1.0.1 2018-11-21 08:30 UTC

README

ImageArtist 是一个 php gd 包装器,使图像处理变得极为简单,我们将 ImageArtist 介绍为 PHP 的 Photoshop

该项目是斯里兰卡 Treinetic (Pvt) Ltd 的一项倡议。通过info@treinetic.com联系我们,让专家们完成您的项目。

Issues Software License Forks Stars Twitter

需求

PHP 5.0 >

可选(考虑安装 imagick 和 pango 以处理复杂的 Unicode 文本)

安装

该包可以通过 composer 安装

$ composer require treinetic/imageartist

使用(让我们深入了解)

非常基础

  • 加载图像,大多数类扩展了 Image 类,所以如果您知道如何加载图像,那么您就知道如何使用大多数库类
$image = new Image("./morning.jpeg");

注意:请记住首先导入(使用)类,有关更完整的代码,请参阅示例文件夹。

  • 图像缩放
$image->scale(40); //scales the image 40%
$image->scaleToHeight(1024); //scales the image keeping height 1024
$image->scaleToWidth(1024); //scales the image keeping width 1024
$image->resize(1024,768); //resizes the image to a given size 
  • 图像属性
$new_wdith = $image->getWidth();
$new_height = $image->getHeight();
  • 更改格式/保存到磁盘
$image->convertTo(IMAGETYPE_PNG);
$image->save("./newImage.jpg",IMAGETYPE_PNG);
  • 方向
$image->rotate(50); 
$image->flipV(); // Vertical Flip
$image->flipH(); // Horizontal Flip
  • 其他有用操作
$base64URL = $image->getDataURI();
/* 
    Image class will return itself for following methods but in Shape classes it will be a new Image 
    to keep the idea of Shape Consistant
 */
$image->crop(100,100,300,300);
$image->merge(new Image("./city.jpg"),10,10);

精彩内容

让我们做一些有意义的事情

  • 创建形状,对于创建自定义形状,您可以直接使用 CircularShape.phpPolygonShape.php。但是,如果您正在寻找尚未存在的标准形状,仍然可以使用 CircularShape.phpPolygonShape.php 来创建它们,但我们鼓励您通过添加这些形状来为项目做出贡献。
  • 让我们创建一个 三角形(还有其他一些预制的形状供您使用)
$triangle = new Triangle("./city.jpg");
$triangle->scale(60);
$triangle->setPointA(20,20,true); //setting point A, i'm using preentages but you can use px as well
$triangle->setPointB(80,20,true);
$triangle->setPointC(50,80,true);
$triangle->build();

  • 创建 自定义形状,让我们看看如何制作一个漂亮的五边形
$pentagon = new PolygonShape("./morning.jpeg");
$pentagon->scale(60);
$pentagon->push(new Node(50,0, Node::$PERCENTAGE_METRICS));
$pentagon->push(new Node(75,50, Node::$PERCENTAGE_METRICS));
$pentagon->push(new Node(62.5,100, Node::$PERCENTAGE_METRICS));
$pentagon->push(new Node(37.5,100, Node::$PERCENTAGE_METRICS));
$pentagon->push(new Node(25,50, Node::$PERCENTAGE_METRICS));
$pentagon->build();

  • 让我们 合并两个三角形
$tr1 = new Triangle("./city.jpg");
$tr1->scale(60);
$tr1->setPointA(0,0,true);
$tr1->setPointB(100,0,true);
$tr1->setPointC(100,100,true);
$tr1->build();

$tr2 = new Triangle("./morning.jpeg");
$tr2->scale(60);
$tr2->setPointA(0,0,true);
$tr2->setPointB(0,100,true);
$tr2->setPointC(100,100,true);
$tr2->build();

$tr1->resize($tr1->getWidth(),$tr2->getHeight());

$img = $tr1->merge($tr2,0,0);
$img->scale(70);

  • 让我们做一些 Photoshop 的事情吧?创建一个 Facebook 封面
/* Let's add an overlay to this */
$overlay = new Overlay($img->getWidth(),$img->getHeight(),new Color(0,0,0,80));
$img->merge($overlay,0,0);
/* hmmm.. lets add a photo */
$circle = new CircularShape("./person.jpg");
$circle->build();
$img = $img->merge($circle,($img->getWidth()-$circle->getWidth())/2,($img->getHeight() - $circle->getHeight())/2);
/* I think I should add some Text */
$textBox = new TextBox(310,40);
$textBox->setColor(Color::getColor(Color::$WHITE));
$textBox->setFont(Font::getFont(Font::$NOTOSERIF_REGULAR));
$textBox->setSize(20);
$textBox->setMargin(2);
$textBox->setText("We Are Team Treinetic");
$img->setTextBox($textBox,($img->getWidth()-$textBox->getWidth())/2,$img->getHeight()* (5/7));

$img->dump(); //development purposes only

变更日志

请参阅CHANGELOG以获取有关最近更改的更多信息。

贡献

请参阅CONTRIBUTING以获取详细信息。

致谢

许可

MIT 许可证(MIT)。有关更多信息,请参阅许可文件