• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Freegle / iznik-server / 418053ef-1b85-44d6-aeef-204bc752e075

26 Jun 2024 12:25PM UTC coverage: 94.239% (-0.6%) from 94.811%
418053ef-1b85-44d6-aeef-204bc752e075

push

circleci

edwh
Test fixes.

0 of 1 new or added line in 1 file covered. (0.0%)

225 existing lines in 5 files now uncovered.

25190 of 26730 relevant lines covered (94.24%)

31.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

57.41
/include/misc/Image.php
1
<?php
2
namespace Freegle\Iznik;
3

4
class Image {
5
    private $data;
6
    public $img;
7

8
    function __construct($data) {
9
        $this->data = $data;
46✔
10
        $this->img = @imagecreatefromstring($data);
46✔
11
    }
12

13
    public function fillTransparent() {
14
        imagealphablending($this->img, false);
14✔
15
        imagesavealpha($this->img, true);
14✔
16
        $transparent = imagecolorallocatealpha($this->img, 255, 255, 255, 127);
14✔
17
        imagefill($this->img, 0, 0, $transparent);
14✔
18
        imagecolortransparent($this->img, $transparent);
14✔
19
    }
20

21
    public function width() {
22
        return(imagesx($this->img));
45✔
23
    }
24

25
    public function height() {
26
        return(imagesy($this->img));
44✔
27
    }
28

29
    public function rotate($deg) {
UNCOV
30
        $this->img = imagerotate($this->img, $deg, 0);
×
31
    }
32

33
    public function scale($width, $height) {
34
        $sw = imagesx($this->img);
14✔
35
        $sh = imagesy($this->img);
14✔
36

37
        if (($width != NULL && $sw != $width) || ($height != NULL && $sh != $height)) {
14✔
38
            # We might have been asked to scale either or both of the width and height.
39
            #
40
            # We want to return even values - if we use the images with ffmpeg, they need to be.
41
            if ($width) {
14✔
42
                $height = intval($sh * $width / $sw + 0.5);
14✔
43
                $height = $height + ($height % 2);
14✔
44
            } else {
45
                $width = $sw;
1✔
46
            }
47

48
            if ($height) {
14✔
49
                $width = intval($sw * $height / $sh + 0.5);
14✔
50
                $width = $width + ($width % 2);
14✔
51
            } else {
52
                $height = $sh;
×
53
            }
54

55
            $height = $height ? $height : $sh;
14✔
56
            $old = $this->img;
14✔
57
            $this->img = @imagecreatetruecolor($width, $height);
14✔
58
            $this->fillTransparent();
14✔
59

60
            # Don't use imagecopyresized here - creates artefacts.
61
            imagecopyresampled($this->img, $old, 0, 0, 0, 0, $width, $height, $sw, $sh);
14✔
62
        }
63
    }
64

65
    public function getData($quality = 75) {
66
        $data = NULL;
15✔
67

68
        if ($this->img) {
15✔
69
            # Get data back as JPEG.  Use default quality.
70
            ob_start();
15✔
71
            imagejpeg($this->img, null, $quality);
15✔
72
            $data = ob_get_contents();
15✔
73
            ob_end_clean();
15✔
74
        }
75

76
        return($data);
15✔
77
    }
78

79
    public function getDataPNG() {
UNCOV
80
        $data = NULL;
×
81

UNCOV
82
        if ($this->img) {
×
UNCOV
83
            ob_start();
×
UNCOV
84
            imagepng($this->img, null);
×
UNCOV
85
            $data = ob_get_contents();
×
UNCOV
86
            ob_end_clean();
×
87
        }
88

UNCOV
89
        return($data);
×
90
    }
91

92
    public function circle($radius) {
UNCOV
93
        $d = imagecreatetruecolor($radius, $radius);
×
UNCOV
94
        imagecopy($d, $this->img, 0, 0, 0, 0, $radius, $radius);
×
95

UNCOV
96
        $mask = imagecreatetruecolor($radius, $radius);
×
UNCOV
97
        $maskTransparent = imagecolorallocate($mask, 255, 0, 255);
×
UNCOV
98
        imagecolortransparent($mask, $maskTransparent);
×
UNCOV
99
        imagefilledellipse($mask, $radius / 2, $radius / 2, $radius, $radius, $maskTransparent);
×
100

UNCOV
101
        imagecopymerge($d, $mask, 0, 0, 0, 0, $radius, $radius, 100);
×
102

UNCOV
103
        $dstTransparent = imagecolorallocate($d, 255, 0, 255);
×
UNCOV
104
        imagefill($d, 0, 0, $dstTransparent);
×
UNCOV
105
        imagefill($d, $radius - 1, 0, $dstTransparent);
×
UNCOV
106
        imagefill($d, 0, $radius - 1, $dstTransparent);
×
UNCOV
107
        imagefill($d, $radius - 1, $radius - 1, $dstTransparent);
×
UNCOV
108
        imagecolortransparent($d, $dstTransparent);
×
109

UNCOV
110
        $this->img = $d;
×
111
    }
112
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc