Skip to content

04d Processing

tei187 edited this page Aug 23, 2024 · 1 revision

Description

Processing the image file is based on one of three available processors:

  • tei187\QrImage2Svg\Processors\GD, which uses standard GD PHP library.
  • tei187\QrImage2Svg\Processors\Imagick, which uses the Imagick PHP extension.
  • tei187\QrImage2Svg\Processors\ImageMagick, which uses ImageMagick CLI interface.

All of these are abstracted from tei187\QrImage2Svg\Processor abstract class. There isn't a lot of wiki to be made here, as the process is rather strictly automated with very few options to manipulate.


Constructor parameters

All processors use the same constructor params.

Parameter Type Default Description
config object N/A tei187\QrImage2Svg\Configuration object.
trimImage bool false Whether or not image should be trimmed on construct. Usable only when you already have defined modules amount in config, in which case it should be set to true.
use tei187\QrImage2Svg\Configuration;
use tei187\QrImage2Svg\Processors\GD;

$config    = new Configuration( /* (...) */ );
$processor = new GD($config);
// creates a GD-based processor with specified config parameters.

Usage

Converting from image to vector

If configuration is properly set and defined, you can use the public output() method to process through the image and create a SVG file. It takes one argument as a boolean flag on whether or not the processor should find the correct number of steps/modules (by default true).

$processor->output();
// yup... that's it...
// i have no idea what to write here...
// take it as it is...

Finding the correct modules count

If you do not want to generate the SVG image but would want to know the number of modules per axis, you can use a suggestTilesQuantity() method. It will return an integer value if analysis was successful, or false if not. Once again, there is no need to run this if you are translating from bitmap to vector images, as this method will launch automatically as default process, unless set otherwise.

$this->suggestTilesQuantity();

The way this method works is:

  1. apply threshold filter and white border trimming
  2. calculate minimal (width / 177) and maximal (width/21) modules sizes.
  3. then a private method __seekBorderEnd() starts, looking for upper left corner mark. It operates on the assumptions of minimal and maximal module size, by parsing through row of the image looking for and counting continued black tiles. This gives us a rough estimate of how many modules there are in each axis.
  4. knowing the assumed size of the corner mark (as well as rough module size), interruptions are counted on the timing sequence line.
  5. the outcomes of point 3 and 4 are then being validated by comparison. If they are equal, method returns and integer value (between 21 and 177). If not, boolean false.

It is as close as I've gotten without making it absurdly wonky.