danack / imagick-demos
Installs: 16
Dependents: 0
Suggesters: 0
Security: 0
Stars: 130
Watchers: 15
Forks: 36
Open Issues: 48
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-11-07 21:20:05 UTC
README
An example of all the Imagick functions. Or at least most of them. The site is hosted at http://phpimagick.com/
The site uses Docker. If you have that on your system, you should be able to run the site locally with:
sh runLocal.sh
The site will be available at the domains:
http://local.phpimagick.com - default version of ImageMagick (currently 7).
http://local.im6.phpimagick.com - explicitly use ImageMagick 6
http://local.im7.phpimagick.com - explicitly use ImageMagick 7
It will take a few minutes (or more) to come up, as it has to compile ImageMagick 6 and 7, and then Imagick. After the first run, these are cached, so should only take a few seconds.
The site is built against the master branch of Imagick at https://github.com/imagick/imagick . As it takes a long time, by default it doesn't rebuild from scratch each time. To force a rebuild against the latest version of Imagick
runRebuildLocal.sh
containers/imagick_php_base_im7/install_imagemagick.sh containers/imagick_php_base_im6/install_imagemagick.sh
Adding examples
There is a list of which examples still need to be added at phpimagick.com/todo.
Here are some instructions on adding examples.
Text example
A text example, is an example that has text as it's output, rather than an image. A complete example for Imagick::getImageMimeType was added in this commit.
The steps involved are:
- Add the example to appropriate list in src/example_list.php
All of the examples are listed in one of getImagickExamples(), getImagickDrawExamples(), getImagickKernelExamples(), getImagickPixelExamples(), getImagickPixelIteratorExamples(), getTutorialExamples().
For each entry in the array, the key is the example name and value is the example controller and example function name. Although most of the time these are the same some examples re-use a controller + function, as there isn't much point duplicating code. e.g. for ImagickDraw 'popClipPath' => 'setClipPath',
- Create a controller
The controller should be in one of the Imagick, ImagickDraw, ImagickKernel, ImagickPixel, ImagickPixelIterator or Tutorial directories under src/ImagickDemo
Usually copying an existing one is a good idea.
The render method of the controller should return a string that demonstrates the result of using the function.
- Mark the example code with a comment with the exact spelling like:
//Example Imagick::getImageMimeType
$imagick = new \Imagick($this->imageControl->getImagePath());
$output = 'Imagick::getImageMimeType result is: ';
$output .= $imagick->getImageMimeType();
return $output;
//Example end
This makes the example code be picked up and shown on the webpage.
Standard image example
A standard image example, is an example that has an image as it's output, where the image is produced by a single simple function. A complete example for Imagick::swirlImageWithMethod was added in this commit.
The steps involved are:
- Add the example to appropriate list in src/example_list.php
All of the examples are listed in one of getImagickExamples(), getImagickDrawExamples(), getImagickKernelExamples(), getImagickPixelExamples(), getImagickPixelIteratorExamples(), getTutorialExamples().
For each entry in the array, the key is the example name and value is the example controller and example function name. Although most of the time these are the same some examples re-use a controller + function, as there isn't much point duplicating code. e.g. for ImagickDraw 'popClipPath' => 'setClipPath',
- Create a controller
Usually copying an existing one is a good idea.
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;
}
}
If the image produced is the same size as the source image, then overloading the useImageControlAsOriginalImage method to return true, will make it possible to hover over the final/original image to compare the two.
- Add example code to
src/ImagickDemo/Imagick/functions.php
The name of the function should be the same name as the controller.
//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
- If necessary create a new example control class.
The getControlType method of the controller, says which control to use.
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()),
];
}
}
The keys in the array returned by SwirlImageWithMethodControl::getValuesForForm
should match the parameter names for the function that produces the image.
Bespoke image example
TODO - write words...