-
Notifications
You must be signed in to change notification settings - Fork 1
/
graphicsmagick.module
1280 lines (1148 loc) · 37.4 KB
/
graphicsmagick.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* @file
* Hooks implementations for the GraphicsMagick module.
*/
declare(strict_types=1);
use graphicsmagick\EffectBase;
use graphicsmagick\OperationBase;
use graphicsmagick\ToolkitInfo;
use graphicsmagick\ToolkitSettings;
use graphicsmagick\Utility\Color;
/**
* Implements hook_autoload_info().
*/
function graphicsmagick_autoload_info(): array {
return array(
'graphicsmagick\Attribute\DefaultSetting' => 'includes/attributes/default_setting.class.inc',
'graphicsmagick\Attribute\EffectOperation' => 'includes/attributes/effect_operation.class.inc',
'graphicsmagick\Effect\Blur' => 'includes/effects/blur.class.inc',
'graphicsmagick\Effect\Despeckle' => 'includes/effects/despeckle.class.inc',
'graphicsmagick\Effect\Emboss' => 'includes/effects/emboss.class.inc',
'graphicsmagick\Effect\Equalize' => 'includes/effects/equalize.class.inc',
'graphicsmagick\Effect\Flip' => 'includes/effects/flip.class.inc',
'graphicsmagick\Effect\Flop' => 'includes/effects/flop.class.inc',
'graphicsmagick\Effect\Gamma' => 'includes/effects/gamma.class.inc',
'graphicsmagick\Effect\Noise' => 'includes/effects/noise.class.inc',
'graphicsmagick\Effect\OilPaint' => 'includes/effects/oil_paint.class.inc',
'graphicsmagick\Effect\Solarize' => 'includes/effects/solarize.class.inc',
'graphicsmagick\Effect\Spread' => 'includes/effects/spread.class.inc',
'graphicsmagick\Effect\Swirl' => 'includes/effects/swirl.class.inc',
'graphicsmagick\EffectBase' => 'includes/effects/effect_base.class.inc',
'graphicsmagick\EffectInterface' => 'includes/effects/effect_interface.class.inc',
'graphicsmagick\MultipleImagesOperationBase' => 'includes/operations/multiple_images_operation_base.class.inc',
'graphicsmagick\Operation\Blur' => 'includes/operations/blur.class.inc',
'graphicsmagick\Operation\Crop' => 'includes/operations/crop.class.inc',
'graphicsmagick\Operation\Desaturate' => 'includes/operations/desaturate.class.inc',
'graphicsmagick\Operation\Despeckle' => 'includes/operations/despeckle.class.inc',
'graphicsmagick\Operation\Edge' => 'includes/operations/edge.class.inc',
'graphicsmagick\Operation\Emboss' => 'includes/operations/emboss.class.inc',
'graphicsmagick\Operation\Enhance' => 'includes/operations/enhance.class.inc',
'graphicsmagick\Operation\Equalize' => 'includes/operations/equalize.class.inc',
'graphicsmagick\Operation\Flip' => 'includes/operations/flip.class.inc',
'graphicsmagick\Operation\Flop' => 'includes/operations/flop.class.inc',
'graphicsmagick\Operation\Gamma' => 'includes/operations/gamma.class.inc',
'graphicsmagick\Operation\Noise' => 'includes/operations/noise.class.inc',
'graphicsmagick\Operation\OilPaint' => 'includes/operations/oil_paint.class.inc',
'graphicsmagick\Operation\Resize' => 'includes/operations/resize.class.inc',
'graphicsmagick\Operation\Rotate' => 'includes/operations/rotate.class.inc',
'graphicsmagick\Operation\Solarize' => 'includes/operations/solarize.class.inc',
'graphicsmagick\Operation\Spread' => 'includes/operations/spread.class.inc',
'graphicsmagick\Operation\Swirl' => 'includes/operations/swirl.class.inc',
'graphicsmagick\OperationBase' => 'includes/operations/operation_base.class.inc',
'graphicsmagick\OperationInterface' => 'includes/operations/operation_interface.class.inc',
'graphicsmagick\SingleImageOperationBase' => 'includes/operations/single_image_operation_base.class.inc',
'graphicsmagick\ToolkitInfo' => 'includes/toolkit_info.class.inc',
'graphicsmagick\ToolkitInfoInterface' => 'includes/toolkit_info_interface.class.inc',
'graphicsmagick\ToolkitSettings' => 'includes/toolkit_settings.class.inc',
'graphicsmagick\ToolkitSettingsInterface' => 'includes/toolkit_settings_interface.class.inc',
'graphicsmagick\Utility\Color' => 'includes/color.class.inc',
);
}
/**
* Implements hook_image_effect_info().
*/
function graphicsmagick_image_effect_info(): array {
$effects = array();
$effects['graphicsmagick_effects_blur'] = array(
'label' => t('Blur'),
'help' => t('This effect will make the image details less distinct using a Gaussian operator.'),
'dimensions passthrough' => TRUE,
'form callback' => 'graphicsmagick_effects_blur_form',
'effect callback' => 'graphicsmagick_effects_blur',
'summary theme' => 'graphicsmagick_effects_blur_summary',
);
$effects['graphicsmagick_effects_despeckle'] = array(
'label' => t('Despeckle'),
'help' => t('This effect will reduce the speckle noise in an image while preserving the original image edges.'),
'dimensions passthrough' => TRUE,
'effect callback' => 'graphicsmagick_effects_despeckle',
);
$effects['graphicsmagick_effects_edge'] = array(
'label' => t('Edge enhance'),
'help' => t('This effect will enhance edges within the image with a convolution filter.'),
'dimensions passthrough' => TRUE,
'form callback' => 'graphicsmagick_effects_edge_form',
'effect callback' => 'graphicsmagick_effects_edge',
'summary theme' => 'graphicsmagick_effects_oil_paint_summary',
);
$effects['graphicsmagick_effects_emboss'] = array(
'label' => t('Emboss'),
'help' => t('This effect will convolve the image using a Gaussian operator, giving the image a three-dimensional effect.'),
'dimensions passthrough' => TRUE,
'form callback' => 'graphicsmagick_effects_emboss_form',
'effect callback' => 'graphicsmagick_effects_emboss',
'summary theme' => 'graphicsmagick_effects_blur_summary',
);
$effects['graphicsmagick_effects_enhance'] = array(
'label' => t('Enhance'),
'help' => t('This effect will improve the quality of a noisy image.'),
'dimensions passthrough' => TRUE,
'effect callback' => 'graphicsmagick_effects_enhance',
);
$effects['graphicsmagick_effects_equalize'] = array(
'label' => t('Equalize'),
'help' => t('This effect will equalize the image histogram.'),
'dimensions passthrough' => TRUE,
'effect callback' => 'graphicsmagick_effects_equalize',
);
$effects['graphicsmagick_effects_flip'] = array(
'label' => t('Vertical mirror'),
'help' => t('This effect will create a vertical mirror image.'),
'dimensions passthrough' => TRUE,
'effect callback' => 'graphicsmagick_effects_flip',
);
$effects['graphicsmagick_effects_flop'] = array(
'help' => t('This effect will create a horizontal mirror image.'),
'dimensions passthrough' => TRUE,
'effect callback' => 'graphicsmagick_effects_flop',
);
$effects['graphicsmagick_effects_gamma'] = array(
'label' => t('Gamma'),
'help' => t("This effect will change the gamma values."),
'dimensions passthrough' => TRUE,
'form callback' => 'graphicsmagick_effects_gamma_form',
'effect callback' => 'graphicsmagick_effects_gamma',
'summary theme' => 'graphicsmagick_effects_gamma_summary',
);
$effects['graphicsmagick_effects_noise'] = array(
'label' => t('Add noise'),
'help' => t("This effect will add random noise to the image."),
'dimensions passthrough' => TRUE,
'form callback' => 'graphicsmagick_effects_noise_form',
'effect callback' => 'graphicsmagick_effects_noise',
'summary theme' => 'graphicsmagick_effects_noise_summary',
);
$effects['graphicsmagick_effects_oil_paint'] = array(
'label' => t('Oil paint'),
'help' => t('This effect will simulate an oil painting.'),
'dimensions passthrough' => TRUE,
'form callback' => 'graphicsmagick_effects_oil_paint_form',
'effect callback' => 'graphicsmagick_effects_oil_paint',
'summary theme' => 'graphicsmagick_effects_oil_paint_summary',
);
$effects['graphicsmagick_effects_solarize'] = array(
'label' => t('Solarize'),
'help' => t('Solarize will apply an effect to the image, similar to the one achieved in a photo darkroom by selectively exposing areas of photo sensitive paper to light.'),
'dimensions passthrough' => TRUE,
'form callback' => 'graphicsmagick_effects_solarize_form',
'effect callback' => 'graphicsmagick_effects_solarize',
'summary theme' => 'graphicsmagick_effects_solarize_summary',
);
$effects['graphicsmagick_effects_spread'] = array(
'label' => t('Spread'),
'help' => t('This effect will randomly displace each pixel in a block defined by the radius.'),
'form callback' => 'graphicsmagick_effects_spread_form',
'effect callback' => 'graphicsmagick_effects_spread',
'summary theme' => 'graphicsmagick_effects_oil_paint_summary',
);
$effects['graphicsmagick_effects_swirl'] = array(
'label' => t('Swirl'),
'help' => t('This effect will swirl the pixels about the center of the image.'),
'form callback' => 'graphicsmagick_effects_swirl_form',
'effect callback' => 'graphicsmagick_effects_swirl',
'summary theme' => 'graphicsmagick_effects_swirl_summary',
);
return $effects;
}
/**
* Implements hook_image_toolkits().
*/
function graphicsmagick_image_toolkits(): array {
try {
$toolkit_info = new ToolkitInfo();
$available = $toolkit_info->isAvailable();
}
catch (\RuntimeException $e) {
watchdog_exception('graphicsmagick', $e);
$available = FALSE;
}
return array(
'graphicsmagick_toolkit' => array(
'title' => t('GraphicsMagick toolkit'),
'available' => $available,
),
);
}
/**
* Implements hook_theme().
*/
function graphicsmagick_theme(): array {
$summary_base = array(
'variables' => array( 'data' => NULL),
'file' => 'includes/graphicsmagick.theme.inc',
);
return array(
'graphicsmagick_effects_blur_summary' => $summary_base,
'graphicsmagick_effects_edge_summary' => $summary_base,
'graphicsmagick_effects_emboss_summary' => $summary_base,
'graphicsmagick_effects_gamma_summary' => $summary_base,
'graphicsmagick_effects_noise_summary' => $summary_base,
'graphicsmagick_effects_oil_paint_summary' => $summary_base,
'graphicsmagick_effects_solarize_summary' => $summary_base,
'graphicsmagick_effects_spread_summary' => $summary_base,
'graphicsmagick_effects_swirl_summary' => $summary_base,
);
}
/**
* Retrieves settings for the GraphicsMagick toolkit.
*
* @return array
* The form array.
*/
function image_graphicsmagick_toolkit_settings(): array {
$settings = new ToolkitSettings();
return $settings->settingsForm();
}
/**
* Retrieves the supported extensions for the GraphicsMagick toolkit.
*
* @return array
* The supported extensions.
*/
function image_graphicsmagick_toolkit_supported_extensions(): array {
try {
$toolkit_info = new ToolkitInfo();
return $toolkit_info->supportedExtensions();
}
catch (\RuntimeException $e) {
watchdog_exception('graphicsmagick', $e);
return array();
}
}
/**
* Loads an image from a file.
*
* @param object $image
* An image object. The $image->handler and $image->format values will be
* populated by this call.
*
* @return bool
* TRUE or FALSE, based on success.
*
* @see image_load()
* @see graphicsmagick_image_load()
*/
function image_graphicsmagick_toolkit_load(object $image): bool {
return graphicsmagick_image_load($image);
}
/**
* Writes an image to a destination file.
*
* @param object $image
* An image object. The $image->handler value will be changed by this call.
* @param string $destination
* A URI or file path where the image should be saved.
*
* @return bool
* TRUE or FALSE, based on success.
*
* @see image_save()
* @see graphicsmagick_image_save()
*/
function image_graphicsmagick_toolkit_save(object $image, string $destination): bool {
return graphicsmagick_image_save($image, $destination);
}
/**
* Gets details about an image.
*
* @param object $image
* An image object.
*
* @return false|array
* FALSE, if the file could not be found or is not an image. Otherwise, a
* keyed array containing information about the image:
* - "width": Width, in pixels.
* - "height": Height, in pixels.
*
* @see image_get_info()
*/
function image_graphicsmagick_toolkit_get_info(object $image): false|array {
$details = array(
'width' => 0,
'height' => 0,
);
try {
$handler = new \Gmagick(backdrop_realpath($image->source));
$details['width'] = $handler->getImageWidth();
$details['height'] = $handler->getImageHeight();
}
catch (\GmagickException) {
// An exception has been thrown when trying to access the image information,
// which could also mean the image file is corrupted. Return FALSE to signal
// an error.
return FALSE;
}
return $details;
}
/**
* Scales an image to the specified size using the GraphicsMagick library.
*
* @param object $image
* An image object. The $image->info['width'] and $image->info['height']
* values will be modified by this call.
* @param int $width
* The new width of the resized image, in pixels.
* @param int $height
* The new height of the resized image, in pixels.
*
* @return bool
* TRUE or FALSE, based on success.
*
* @see image_resize()
*/
function image_graphicsmagick_toolkit_resize(object $image, int $width, int $height): bool {
if ($operation = OperationBase::create('resize')) {
return $operation->apply($image, array('width' => $width, 'height' => $height));
}
return FALSE;
}
/**
* Rotates an image the given number of degrees.
*
* @param object $image
* An image object. The $image->info['width'] and $image->info['height']
* values will be modified by this call.
* @param int $degrees
* The number of (clockwise) degrees to rotate the image.
* @param int|string|null $background
* A hexadecimal value specifying the background color to use for the
* uncovered area of the image after the rotation, for example 0x000000 for
* black or 0xff00ff for magenta. The default value is #FFFFFF.
*
* @return bool
* TRUE or FALSE, based on success.
*
* @see image_rotate()
*/
function image_graphicsmagick_toolkit_rotate(object $image, int $degrees, int|string|null $background): bool {
try {
$color = Color::toHex($background);
if ($operation = OperationBase::create('rotate')) {
return $operation->apply($image, array('degrees' => $degrees, 'background' => $color));
}
}
catch (\InvalidArgumentException $e) {
watchdog_exception('graphicsmagick', $e);
return FALSE;
}
return FALSE;
}
/**
* Crops an image using the GraphicsMagick library.
*
* @param object $image
* An image object. The $image->info['width'] and $image->info['height']
* values will be modified by this call.
* @param int $x
* The starting x offset at which to start the crop, in pixels.
* @param int $y
* The starting y offset at which to start the crop, in pixels.
* @param int $width
* The width of the cropped area, in pixels.
* @param int $height
* The height of the cropped area, in pixels.
*
* @return bool
* TRUE or FALSE, based on success.
*
* @see image_crop()
*/
function image_graphicsmagick_toolkit_crop(object $image, int $x, int $y, int $width, int $height): bool {
if ($operation = OperationBase::create('crop')) {
return $operation->apply($image, array('x' => $x, 'y' => $y, 'width' => $width, 'height' => $height));
}
return FALSE;
}
/**
* Converts an image to grayscale.
*
* @param object $image
* An image object.
*
* @return bool
* TRUE or FALSE, based on success.
*
* @see image_desaturate()
*/
function image_graphicsmagick_toolkit_desaturate(object $image): bool {
if ($operation = OperationBase::create('desaturate')) {
return $operation->apply($image);
}
return FALSE;
}
/**
* Blurs an image.
*
* @param object $image
* An image object.
* @param float $radius
* The Gaussian radius.
* @param float $sigma
* The Gaussian sigma.
*
* @return bool
* TRUE or FALSE, based on success.
*/
function image_graphicsmagick_toolkit_blur(object $image, float $radius, float $sigma): bool {
if ($operation = OperationBase::create('blur')) {
return $operation->apply($image, array('radius' => $radius, 'sigma' => $sigma));
}
return FALSE;
}
/**
* Reduces the speckle noise in an image.
*
* @param object $image
* An image object.
*
* @return bool
* TRUE or FALSE, based on success.
*/
function image_graphicsmagick_toolkit_despeckle(object $image): bool {
if ($operation = OperationBase::create('despeckle')) {
return $operation->apply($image);
}
return FALSE;
}
/**
* Enhances the image edges.
*
* @param object $image
* An image object.
* @param float $radius
* The operation radius.
*
* @return bool
* TRUE or FALSE, based on success.
*/
function image_graphicsmagick_toolkit_edge(object $image, float $radius): bool {
if ($operation = OperationBase::create('edge')) {
return $operation->apply($image, array('radius' => $radius));
}
return FALSE;
}
/**
* Embosses an image.
*
* @param object $image
* An image object.
* @param float $radius
* The Gaussian radius.
* @param float $sigma
* The Gaussian sigma.
*
* @return bool
* TRUE on success, FALSE on failure to apply the effect.
*/
function image_graphicsmagick_toolkit_emboss(object $image, float $radius, float $sigma): bool {
if ($operation = OperationBase::create('emboss')) {
return $operation->apply($image, array('radius' => $radius, 'sigma' => $sigma));
}
return FALSE;
}
/**
* Enhances an image.
*
* @param object $image
* An image object.
*
* @return bool
* TRUE on success, FALSE on failure to blur the image.
*/
function image_graphicsmagick_toolkit_enhance(object $image): bool {
if ($operation = OperationBase::create('enhance')) {
return $operation->apply($image);
}
return FALSE;
}
/**
* Equalizes an image.
*
* @param object $image
* An image object.
*
* @return bool
* TRUE on success, FALSE on failure to apply the effect.
*/
function image_graphicsmagick_toolkit_equalize(object $image): bool {
if ($operation = OperationBase::create('equalize')) {
return $operation->apply($image);
}
return FALSE;
}
/**
* Creates a vertical mirror image.
*
* @param object $image
* An image object.
*
* @return bool
* TRUE on success, FALSE on failure to apply the effect.
*/
function image_graphicsmagick_toolkit_flip(object $image): bool {
if ($operation = OperationBase::create('flip')) {
return $operation->apply($image);
}
return FALSE;
}
/**
* Creates a horizontal mirror image.
*
* @param object $image
* An image object.
*
* @return bool
* TRUE on success, FALSE on failure to apply the effect.
*/
function image_graphicsmagick_toolkit_flop(object $image): bool {
if ($operation = OperationBase::create('flop')) {
return $operation->apply($image);
}
return FALSE;
}
/**
* Changes the image gamma value.
*
* @param object $image
* An image object.
* @param float $gamma
* The new gamma value.
*
* @return bool
* TRUE on success, FALSE on failure to apply the effect.
*/
function image_graphicsmagick_toolkit_gamma(object $image, float $gamma): bool {
if ($operation = OperationBase::create('gamma')) {
return $operation->apply($image, array('gamma' => $gamma));
}
return FALSE;
}
/**
* Adds random noise.
*
* @param object $image
* An image object.
* @param int $noise
* The noise type.
*
* @return bool
* TRUE on success, FALSE on failure to apply the effect.
*/
function image_graphicsmagick_toolkit_noise(object $image, int $noise): bool {
if ($operation = OperationBase::create('noise')) {
return $operation->apply($image, array('noise' => $noise));
}
return FALSE;
}
/**
* Image effect callback; simulate an oil painting.
*
* @param object $image
* An image object.
* @param float $radius
* The radius of the circular region used to calculate the most frequently
* used color.
*
* @return bool
* TRUE on success, FALSE on failure to apply the effect.
*/
function image_graphicsmagick_toolkit_oil_paint(object $image, float $radius): bool {
if ($operation = OperationBase::create('oil_paint')) {
return $operation->apply($image, array('radius' => $radius));
}
return FALSE;
}
/**
* Simulates a solarize effect.
*
* @param object $image
* An image object.
* @param int $level
* An integer representing the level of the effect.
*
* @return bool
* TRUE on success, FALSE on failure to apply the effect.
*/
function image_graphicsmagick_toolkit_solarize(object $image, int $level): bool {
if ($operation = OperationBase::create('solarize')) {
return $operation->apply($image, array('level' => $level));
}
return FALSE;
}
/**
* Randomly displaces each pixel in a circular region.
*
* @param object $image
* An image object.
*
* @param float $radius
* The radius of the circular region where the pixels are randomly displaced.
*
* @return bool
* TRUE on success, FALSE on failure to apply the effect.
*/
function image_graphicsmagick_toolkit_spread(object $image, float $radius): bool {
if ($operation = OperationBase::create('spread')) {
return $operation->apply($image, array('radius' => $radius));
}
return FALSE;
}
/**
* Swirls the pixels about the center of the image.
*
* @param object $image
* An image object.
* @param float $degrees
* The sweep of the arc through which each pixel is moved.
*
* @return bool
* TRUE on success, FALSE on failure to apply the effect.
*/
function image_graphicsmagick_toolkit_swirl(object $image, float $degrees): bool {
if ($operation = OperationBase::create('swirl')) {
return $operation->apply($image, array('degrees' => $degrees));
}
return FALSE;
}
/**
* Form structure for the blur effect.
*
* Note that this is not a complete form; it only contains the portion of the
* form for configuring the effect options. Therefore, it does not need to
* include metadata about the effect, nor a submit button.
*
* @param array $data
* The current configuration for this effect.
*/
function graphicsmagick_effects_blur_form(array $data): array {
if ($effect = EffectBase::create('blur')) {
return $effect->settingsForm($data);
}
return array();
}
/**
* Image effect callback; blur an image.
*
* @param object $image
* An image object.
* @param array $data
* An array of attributes to use when performing the blur effect with the
* following items:
* - "radius": The Gaussian radius.
* - "sigma": The Gaussian sigma.
*
* @return bool
* TRUE on success, FALSE on failure to apply the effect.
*/
function graphicsmagick_effects_blur(object $image, array $data): bool {
if ($effect = EffectBase::create('blur')) {
return $effect->apply($image, $data);
}
return FALSE;
}
/**
* Image effect callback; reduce the speckle noise in an image.
*
* @param object $image
* An image object.
*
* @return bool
* TRUE on success, FALSE on failure to apply the effect.
*/
function graphicsmagick_effects_despeckle(object $image): bool {
if ($effect = EffectBase::create('despeckle')) {
return $effect->apply($image);
}
return FALSE;
}
/**
* Form structure for the edge effect.
*
* Note that this is not a complete form; it only contains the portion of the
* form for configuring the effect options. Therefore, it does not need to
* include metadata about the effect, nor a submit button.
*
* @param array $data
* An array of attributes to use when performing the effect with the
* following items:
* - "radius": the operation radius.
*/
function graphicsmagick_effects_edge_form(array $data): array {
if ($effect = EffectBase::create('edge')) {
return $effect->settingsForm($data);
}
return array();
}
/**
* Image effect callback; enhance the image edges.
*
* @param object $image
* An image object.
* @param $data
* An array of attributes to use when performing the effect with the
* following items:
* - "radius": the operation radius.
*
* @return bool
* TRUE on success, FALSE on failure to apply the effect.
*/
function graphicsmagick_effects_edge(object $image, array $data): bool {
if ($effect = EffectBase::create('edge')) {
return $effect->apply($image, $data);
}
return FALSE;
}
/**
* Form structure for the emboss effect.
*
* Note that this is not a complete form; it only contains the portion of the
* form for configuring the effect options. Therefore, it does not need to
* include metadata about the effect, nor a submit button.
*
* @param array $data
* The current configuration for this effect.
*/
function graphicsmagick_effects_emboss_form(array $data): array {
if ($effect = EffectBase::create('emboss')) {
return $effect->settingsForm($data);
}
return array();
}
/**
* Image effect callback; emboss an image.
*
* @param object $image
* An image object.
* @param array $data
* An array of attributes to use when performing the emboss effect with the
* following items:
* - "radius": The Gaussian radius.
* - "sigma": The Gaussian sigma.
*
* @return bool
* TRUE on success, FALSE on failure to apply the effect.
*/
function graphicsmagick_effects_emboss(object $image, array $data): bool {
if ($effect = EffectBase::create('emboss')) {
return $effect->apply($image, $data);
}
return FALSE;
}
/**
* Image effect callback; enhance an image.
*
* @param object $image
* An image object.
* @param array $data
* An array of attributes to use when enhancing an image. No attributes are
* currently used for this effect.
*
* @return bool
* TRUE on success, FALSE on failure to blur the image.
*/
function graphicsmagick_effects_enhance(object $image, array $data): bool {
if ($effect = EffectBase::create('enhance')) {
return $effect->apply($image, $data);
}
return FALSE;
}
/**
* Image effect callback; equalize an image.
*
* @param object $image
* An image object.
* @param array $data
* An array of attributes to use when equalizing an image. No attributes are
* currently used for this effect.
*
* @return bool
* TRUE on success, FALSE on failure to apply the effect.
*/
function graphicsmagick_effects_equalize(object $image, array $data): bool {
if ($effect = EffectBase::create('equalize')) {
return $effect->apply($image, $data);
}
return FALSE;
}
/**
* Image effect callback; create a vertical mirror image.
*
* @param object $image
* An image object.
* @param array $data
* An array of attributes to use when creating a vertical mirror image. No
* attributes are currently used for this effect.
*
* @return bool
* TRUE on success, FALSE on failure to apply the effect.
*/
function graphicsmagick_effects_flip(object $image, array $data): bool {
if ($effect = EffectBase::create('flip')) {
return $effect->apply($image, $data);
}
return FALSE;
}
/**
* Image effect callback; create a horizontal mirror image.
*
* @param object $image
* An image object.
* @param array $data
* An array of attributes to use when creating a horizontal mirror image. No
* attributes are currently used for this effect.
*
* @return bool
* TRUE on success, FALSE on failure to apply the effect.
*/
function graphicsmagick_effects_flop(object $image, array $data): bool {
if ($effect = EffectBase::create('flop')) {
return $effect->apply($image, $data);
}
return FALSE;
}
/**
* Form structure for the gamma effect.
*
* Note that this is not a complete form; it only contains the portion of the
* form for configuring the effect options. Therefore, it does not need to
* include metadata about the effect, nor a submit button.
*
* @param array $data
* The current configuration for this effect.
*/
function graphicsmagick_effects_gamma_form(array $data): array {
if ($effect = EffectBase::create('gamma')) {
return $effect->settingsForm($data);
}
return array();
}
/**
* Image effect callback; change the image gamma value.
*
* @param object $image
* An image object.
* @param array $data
* An array of attributes to use when changing the gamma value with the
* following items:
* - "gamma": The new gamma value.
*
* @return bool
* TRUE on success, FALSE on failure to apply the effect.
*/
function graphicsmagick_effects_gamma(object $image, array $data): bool {
if ($effect = EffectBase::create('gamma')) {
return $effect->apply($image, $data);
}
return FALSE;
}
/**
* Form structure for the noise effect.
*
* Note that this is not a complete form; it only contains the portion of the
* form for configuring the effect options. Therefore, it does not need to
* include metadata about the effect, nor a submit button.
*
* @param array $data
* The current configuration for this effect.
*/
function graphicsmagick_effects_noise_form(array $data): array {
if ($effect = EffectBase::create('noise')) {
return $effect->settingsForm($data);
}
return array();
}
/**
* Image effect callback; add random noise.
*
* @param object $image
* An image object.
* @param array $data
* An array of attributes to use when applying the effect with the following
* items:
* - "noise": The noise type.
*
* @return bool
* TRUE on success, FALSE on failure to apply the effect.
*/
function graphicsmagick_effects_noise(object $image, array $data): bool {
if ($effect = EffectBase::create('noise')) {
return $effect->apply($image, $data);
}
return FALSE;
}
/**
* Form structure for the oil painting effect.
*
* Note that this is not a complete form; it only contains the portion of the
* form for configuring the effect options. Therefore, it does not need to
* include metadata about the effect, nor a submit button.