danack / imagick-demos
Requires
- ext-curl: *
- ext-dom: *
- ext-json: *
- danack/configurator: 1.1.1
- danack/console: ^2.6.0
- danack/datatype: ^0.5.1
- danack/esprintf: 2.0.0
- danack/filefilter: ^0.0.1
- danack/slim-auryn-invoker: dev-master
- danack/var-map: ^0.6.0
- dmore/chrome-mink-driver: ^2.8
- fluentdom/fluentdom: v4.1.3
- nikic/fast-route: ^1.0
- predis/predis: ^1.0.1
- rdlowrey/auryn: ^1.3.0
- room11/caching: ^0.0.4
- room11/http: ^0.2.1
- slim/slim: 3.7.0
- twig/twig: ^2.11
Requires (Dev)
- danack/coding-standard: 0.3.0
- mikey179/vfsstream: 1.4.0
- phpstan/phpstan-strict-rules: ^0.12.9
- phpunit/phpunit: 9.5.6
- slevomat/coding-standard: ^7.0.13
- squizlabs/php_codesniffer: ^3.6.0
- yoast/yoastcs: 2.1.0
This package is auto-updated.
Last update: 2024-09-07 20:52:46 UTC
README
所有 Imagick 函数的示例。或者至少是大部分。该网站托管在 http://phpimagick.com/
该网站使用 Docker。如果您系统中有 Docker,您应该能够使用以下命令在本地上运行该网站:
sh runLocal.sh
网站将在以下域名下可用:
http://local.phpimagick.com - 默认版本的 ImageMagick(目前为 7)。
http://local.im6.phpimagick.com - 显式使用 ImageMagick 6
http://local.im7.phpimagick.com - 显式使用 ImageMagick 7
它需要几分钟(或更长时间)才能启动,因为它需要编译 ImageMagick 6 和 7,然后是 Imagick。第一次运行后,这些将被缓存,所以应该只需要几秒钟。
该网站针对 Imagick 在 https://github.com/imagick/imagick 的 master 分支构建。因为它需要很长时间,所以默认情况下,它不会每次都从头开始重建。要强制针对 Imagick 的最新版本重新构建
runRebuildLocal.sh
containers/imagick_php_base_im7/install_imagemagick.sh containers/imagick_php_base_im6/install_imagemagick.sh
添加示例
有关哪些示例还需要添加的列表,请参阅 phpimagick.com/todo。
以下是一些添加示例的说明。
文本示例
文本示例是指输出文本而不是图像的示例。Imagick::getImageMimeType 的完整示例 在此提交中添加。
涉及步骤
- 将示例添加到 src/example_list.php 中的适当列表
所有示例都列在 getImagickExamples()、getImagickDrawExamples()、getImagickKernelExamples()、getImagickPixelExamples()、getImagickPixelIteratorExamples()、getTutorialExamples() 之一中。
对于数组中的每个条目,键是示例名称,值是示例控制器和示例函数名称。尽管大多数情况下这些是相同的,但某些示例会重复使用控制器 + 函数,因为没有太多理由重复代码。例如,对于 ImagickDraw 'popClipPath' => 'setClipPath',
- 创建控制器
控制器应位于 src/ImagickDemo 下的 Imagick、ImagickDraw、ImagickKernel、ImagickPixel、ImagickPixelIterator 或 Tutorial 目录之一中
通常复制现有的一个是好主意。
控制器的 render 方法应返回一个字符串,该字符串演示了使用该函数的结果。
- 用带有精确拼写的注释标记示例代码
//Example Imagick::getImageMimeType
$imagick = new \Imagick($this->imageControl->getImagePath());
$output = 'Imagick::getImageMimeType result is: ';
$output .= $imagick->getImageMimeType();
return $output;
//Example end
这使得示例代码被选中并显示在网页上。
标准图像示例
标准图像示例是指输出图像而不是图像的示例,其中图像由单个简单函数生成。Imagick::swirlImageWithMethod 的完整示例 在此提交中添加。
涉及步骤
- 将示例添加到 src/example_list.php 中的适当列表
所有示例都列在 getImagickExamples()、getImagickDrawExamples()、getImagickKernelExamples()、getImagickPixelExamples()、getImagickPixelIteratorExamples()、getTutorialExamples() 之一中。
对于数组中的每个条目,键是示例名称,值是示例控制器和示例函数名称。尽管大多数情况下这些是相同的,但某些示例会重复使用控制器 + 函数,因为没有太多理由重复代码。例如,对于 ImagickDraw 'popClipPath' => 'setClipPath',
- 创建控制器
通常复制现有的一个是好主意。
class swirlImageWithMethod extends \ImagickDemo\Example
{
public function renderTitle(): string
{
return "Imagick::swirlImageWithMethod";
}
public function useImageControlAsOriginalImage()
{
return true;
}
public static function getParamType(): string
{
return SwirlImageWithMethodControl::class;
}
}
如果生成的图像与源图像大小相同,则通过覆盖 useImageControlAsOriginalImage 方法返回 true,可以悬停在最终/原始图像上以比较两者。
- 将示例代码添加到
src/ImagickDemo/Imagick/functions.php
函数的名称应与控制器的名称相同。
//Example Imagick::swirlImageWithMethod
function swirlImageWithMethod($image_path, $swirl, int $interpolate_method)
{
$imagick = new \Imagick(realpath($image_path));
$imagick->swirlImageWithMethod($swirl, $interpolate_method);
header("Content-Type: image/jpeg");
echo $imagick->getImageBlob();
}
//Example end
- 如有必要,创建一个新的示例控制类。
控制器的 getControlType 方法说明使用哪个控件。
class SwirlImageWithMethodControl
{
use SafeAccess;
use CreateFromVarMap;
use ToArray;
use InputParameterListFromAttributes;
public function __construct(
#[Swirl('swirl')]
private string $swirl,
#[InterpolateType('interpolate_method')]
private int $interpolate_method,
#[Image('image_path')]
private string $image_path,
) {
}
public function getValuesForForm(): array
{
return [
'swirl' => $this->swirl,
'interpolate_method' => getOptionFromOptions($this->interpolate_method, getInterpolateOptions()),
'image_path' => getOptionFromOptions($this->image_path, getImagePathOptions()),
];
}
}
SwirlImageWithMethodControl::getValuesForForm
返回的数组中的键应与生成图像的函数的参数名称匹配。
定制图像示例
待办 - 添加文字...