File: 266_ImagickDraw_getFontResolution_basic.phpt

package info (click to toggle)
php-imagick 3.8.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,288 kB
  • sloc: ansic: 17,876; php: 1,440; xml: 444; pascal: 80; sh: 19; makefile: 2
file content (71 lines) | stat: -rw-r--r-- 1,911 bytes parent folder | download | duplicates (3)
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
--TEST--
Test ImagickDraw, getFontResolution
--SKIPIF--
<?php
die('skip test fails with php7.4 on debian-ish systems');
require_once(dirname(__FILE__) . '/skipif.inc');
checkClassMethods('ImagickDraw', array('getFontResolution', 'setFontResolution'));
?>
--FILE--
<?php

require_once(dirname(__FILE__) . '/functions.inc');

$backgroundColor = 'rgb(225, 225, 225)';
$strokeColor = 'rgb(0, 0, 0)';
$fillColor = 'DodgerBlue2';


$draw = new \ImagickDraw();
setFontForImagickDraw($draw);

$draw->setStrokeColor($strokeColor);
$draw->setFillColor($fillColor);

$draw->setStrokeWidth(2);
$draw->setFontSize(72);

$fontResolution = $draw->getFontResolution();

if (isset($fontResolution["x"]) == false || isset($fontResolution["y"]) == false) {
	echo "$fontResolution doesn't contain expected values:\n";
	var_dump($fontResolution);
}

if ($fontResolution["x"] < 8 || $fontResolution["x"] > 100) {
	echo "Font resolution x outside expected range: ".$fontResolution["x"]."\n";
}
if ($fontResolution["y"] < 8 || $fontResolution["y"] > 100) {
	echo "Font resolution y outside expected range: ".$fontResolution["y"]."\n";
}

$resolutionToSet = 36;

$draw->setFontResolution($resolutionToSet, $resolutionToSet);
$fontResolution = $draw->getFontResolution();

if (abs($fontResolution["x"] - $resolutionToSet) > 0.0001) {
	echo "Font resolution x after set is not $resolutionToSet instead: ".$fontResolution["x"]."\n";
}
if (abs($fontResolution["y"] - $resolutionToSet) > 0.0001) {
	echo "Font resolution y after set is not $resolutionToSet instead: ".$fontResolution["y"]."\n";
}

$draw->line(125, 70, 100, 50);
$draw->annotation(50, 32, "Lorem Ipsum!");

$imagick = new \Imagick();
$imagick->newImage(500, 500, $backgroundColor);
$imagick->setImageFormat("png");
$imagick->drawImage($draw);


$bytes = $imagick->getImageBlob();
if (strlen($bytes) <= 0) { echo "Failed to generate image.";} 


echo "Ok";
?>

--EXPECTF--
Ok