r0adrunn3r / easy-pnp
EasyPnP是一个PHP类,允许轻松地从图像生成PnP(打印并玩)游戏的PDF。
0.6.2
2019-07-18 14:16 UTC
Requires
- setasign/fpdf: >=1.8.1
This package is auto-updated.
Last update: 2024-09-19 01:56:01 UTC
README
EasyPnP是一个PHP类,允许轻松地从图像生成PnP(打印并玩)游戏的PDF。我制作它是为了帮助我从一组卡片和标记图像为我的项目生成精确的PDF,因为我想要更多的控制,所以我决定分享它,也许有人会认为它有用。
显然这个类还远非完美,但对我来说可以完成工作 :) 唯一的依赖项是fpdf
安装
从GitHub下载
您可以直接从GitHub下载该类并在您的项目中使用它,唯一的依赖项是fpdf,所以请确保包含它!
Composer
如果您使用Composer来管理依赖项,可以使用以下命令:
$ composer require r0adrunn3r/easy-pnp
或者您可以在您的composer.json中包含以下内容:
{
"require": {
"r0adrunn3r/easy-pnp": ">=0.6.1"
}
}
如何使用
单位是毫米(我是意大利人),但底层的fpdf也支持英寸,修改类以支持其他单位并不太难,如果有人需要并且不知道如何操作,只需打开一个问题,我会添加它 :)
使用各种配置的示例
require_once('./fpdf.php'); require_once('./EasyPnP.php'); $card_width = 30; // 30mm $card_height = 60; //60mm //Arguments are the padding of the pages and the margins of the images respectively. $epnp = new EasyPnP(5,3); //You can use URLs or Paths $img_array = array( "http://mysite.com/cards/image1.png", "http://mysite.com/cards/image2.png", "./cards/image3.png" ); $epnp->WriteImages($card_width, $card_height, $img_array); //---------------------------------------------------- //Static helper method for generating an array of imgs paths from a folder $img_array_folder = EasyPnP::FilesArrayFromDir("./cards"); $epnp->WriteImages($card_width, $card_height, $img_array_folder); //---------------------------------------------------- /*If your images are organized with a sequence number you can use the FilesArrayFromPattern static helper method This call for exaple is equivalent to: $array_img_pattern = array( "./tokens/token_2.png", "./tokens/token_3.png", "./tokens/token_4.png", "./tokens/token_5.png", "./tokens/token_6.png", ); 5 images, counter starts from 2 */ $array_img_pattern = EasyPnP::FilesArrayFromPattern("./tokens/token_%.png",5, 2); $epnp->WriteImages(20, 20, $array_img_pattern); //---------------------------------------------------- //You can also use generated images (with PHP GD for example) but *BEFORE* use them make sure to specify the type of file to EasyPnP $epnp->SetFileType('png'); $img_array_php = array("http://xyz.com/cards.php?id=45","http://xyz.com/cards.php?id=47"); $epnp->WriteImages($card_width, $card_height, $img_array_php); //---------------------------------------------------- //You can also create a front & back pdf ready to print, the fourth argument can be a single image path or an array of backs, if so the array of front and the array of backs must have the same size $epnp->WriteImagesDoubleSide($card_width, $card_height, $img_array, "./back.png"); //---------------------------------------------------- //After all the images are writed out you can output the pdf, the first argument is for forcing the download instead of opend it inside the browser. $pdf->GeneratePDF(true, "printable.pdf");
您可以在examples文件夹中找到更多示例,用于测试(包括fpdf的一个版本)。
示例文件夹中的所有卡片均来自https://code.google.com/archive/p/vector-playing-cards/