Git Product home page Git Product logo

imagickdemos's Introduction

Imagick-demos

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:

  1. 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',

  1. 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.

  1. 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:

  1. 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',

  1. 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.

  1. 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
  1. 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...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.