source: spip-zone/_plugins_/filtres_images_vectorise/trunk/lib/geometrize/readme.md @ 116199

Last change on this file since 116199 was 116199, checked in by cedric@…, 21 months ago

Un plugin pour vectoriser en SVG des images bitmap, qui propose 4 nouveaux filtres

  • extraire_palette_couleurs permet d'extraire une palette de couleur d'une image (par defaut les 3 couleurs les plus representees) en utilisant un calcul des couleurs dominantes par partitionnement en k-moyennes

`
<BOUCLE_palette(POUR){tableau #FICHIER|extraire_palette_couleurs{3}}>
<div style="display: inline-block;width: 30px;height: 15px;background-color: #VALEUR;"></div>
</BOUCLE_palette>
`

  • image_geometrize permet de creer une image SVG approchante de l'image d'origine en utilisant le lib GeometrizePHP https://github.com/Cerdic/geometrize-php/ (attention methode gourmande en temps de calcul)
  • image_potrace permet de generer un trace SVG depuis l'image d'origine, a l'aide de Potracio PHP qui est un portage PHP de PotRace? https://seenthis.net/messages/645575
  • image_geopotrize combine les 2 techniques : un background geometrize qui n'a pas besoin d'un grand nombre de shapes et un trace potrace superpose/mixe

Les 3 filtres ont tout un tas d'option pour qui veut jouer avec, mais les reglages par defaut permettent d'avoir immediatement un joli resultat exploitable
A noter que pour image_geometrize, le temps de calcul peut depasser les 30s pour generer le nombre de shapes demandees, selon les reglages utilises.
Dans ce cas le calcul est arrete au bout de 20s, on stocke et on renvoie l'image provisoire incomplete, et on stocke l'etat du calcul qui reprendra au prochain calcul de la page.

(J'evite les screenshots dans le message de commit mais le coeur y est)

File size: 4.0 KB
Line 
1# GeometrizePHP
2
3This is a PHP Port, optimization and refactoring of the https://github.com/Tw1ddle/geometrize-haxe
4The initial code has been auto generated with Haxe and then cleaned and optimized for performance and readability purposes
5
6# Usage
7
8```
9use \Cerdic\Geometrize\Shape\ShapeTypes;
10use \Cerdic\Geometrize\Bitmap;
11use \Cerdic\Geometrize\ImageRunner;
12
13include_once "geometrize.init.php";
14
15$geometrize_options = [
16        "shapeTypes" => [ShapeTypes::T_TRIANGLE],
17        "alpha" => 255,
18        "candidateShapesPerStep" => 100,
19        "shapeMutationsPerStep" => 50,
20];
21
22
23$bitmap = Bitmap::createFromImageFile($imageFile);
24$runner = new ImageRunner($bitmap);
25
26$nb_shapes = 100;
27$score = $runner->steps($geometrize_options, $nb_shapes);
28
29$svg = $runner->exportToSVG();
30file_put_contents($fileSVG, $svg);
31
32```
33
34### Shapes
35
36Provide an array with the list of the shapes you want to use.
37Availables shapes are :
38* `ShapeTypes::T_RECTANGLE`
39* `ShapeTypes::T_ROTATED_RECTANGLE`
40* `ShapeTypes::T_TRIANGLE`
41* `ShapeTypes::T_ELLIPSE`
42* `ShapeTypes::T_ROTATED_ELLIPSE`
43* `ShapeTypes::T_CIRCLE`
44* `ShapeTypes::T_LINE`
45* `ShapeTypes::T_QUADRATIC_BEZIER`
46
47Triangles ar the much faster to be computed.
48Then comes Rectangles, Rotated Rectangles and Lines which are still not too bad.
49Ellipses, Circles and Bezier curves are much slower.
50
51In general Triangles alone gives the best compromise for result vs time computing.
52
53
54### Background Color
55
56Not setting any background Color, Geometrize will determine the dominant color and use it as a background.
57
58You can also remove any background color when initializing the Runner:
59```
60$runner = new ImageRunner($bitmap, false);
61```
62
63Or fix an arbitrary background color:
64
65```
66// set a background color
67$red = 127;
68$green = 127;
69$blue = 127;
70$alpha = 255;
71$background = ($red << 24) + ($green << 16) + ($blue << 8) + $alpha;
72$runner = new ImageRunner($bitmap, $background);
73```
74
75## Performance considerations
76
77For performance purposes you should not operate directly on the full-sized image but on a thumbnail,
78like 128px, 256px or 512px wide depending on the quality of the rendering you want:
79
80```
81// TODO create a thumbnail and store it into $imageFileTumbnail
82$bitmap = Bitmap::createFromImageFile($imageFileTumbnail);
83$runner = new ImageRunner($bitmap, $background);
84
85$nb_shapes = 100;
86$score = $runner->steps($geometrize_options, $nb_shapes);
87
88// export rescaling the SVG to the original Image size
89$svg = $runner->exportToSVG($originalWidth, $originalHeight);
90
91```
92
93
94# Screenshots
95
96All rendering with 1200 triangles
97
98
99![JPG](https://raw.githubusercontent.com/Cerdic/geometrize-php/master/screenshots/screenshot-1.jpg)
100[![SVG 1200 triangles](https://raw.githubusercontent.com/Cerdic/geometrize-php/master/screenshots/screenshot-1-geo.png)](https://github.com/Cerdic/geometrize-php/blob/master/screenshots/screenshot-1-geo.svg)
101
102----
103
104![JPG](https://raw.githubusercontent.com/Cerdic/geometrize-php/master/screenshots/screenshot-2.jpg)
105[![SVG 1200 triangles](https://raw.githubusercontent.com/Cerdic/geometrize-php/master/screenshots/screenshot-2-geo.png)](https://github.com/Cerdic/geometrize-php/blob/master/screenshots/screenshot-1-geo.svg)
106
107----
108
109![JPG](https://raw.githubusercontent.com/Cerdic/geometrize-php/master/screenshots/screenshot-3.jpg)
110[![SVG 1200 triangles](https://raw.githubusercontent.com/Cerdic/geometrize-php/master/screenshots/screenshot-3-geo.png)](https://github.com/Cerdic/geometrize-php/blob/master/screenshots/screenshot-3-geo.svg)
111
112----
113
114![JPG](https://raw.githubusercontent.com/Cerdic/geometrize-php/master/screenshots/screenshot-4.jpg)
115[![SVG 1200 triangles](https://raw.githubusercontent.com/Cerdic/geometrize-php/master/screenshots/screenshot-4-geo.png)](https://github.com/Cerdic/geometrize-php/blob/master/screenshots/screenshot-4-geo.svg)
116
117----
118
119![JPG](https://raw.githubusercontent.com/Cerdic/geometrize-php/master/screenshots/screenshot-5.jpg)
120[![SVG 1200 triangles](https://raw.githubusercontent.com/Cerdic/geometrize-php/master/screenshots/screenshot-5-geo.png)](https://github.com/Cerdic/geometrize-php/blob/master/screenshots/screenshot-5-geo.svg)
121
122
Note: See TracBrowser for help on using the repository browser.