txmodxoops /
tdmcreate
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
| 1 | <?php |
||||||||||
| 2 | |||||||||||
| 3 | namespace XoopsModules\Tdmcreate\Common; |
||||||||||
| 4 | |||||||||||
| 5 | /* |
||||||||||
| 6 | You may not change or alter any portion of this comment or credits |
||||||||||
| 7 | of supporting developers from this source code or any supporting source code |
||||||||||
| 8 | which is considered copyrighted (c) material of the original comment or credit authors. |
||||||||||
| 9 | |||||||||||
| 10 | This program is distributed in the hope that it will be useful, |
||||||||||
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||||||
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||||||||
| 13 | */ |
||||||||||
| 14 | |||||||||||
| 15 | /** |
||||||||||
| 16 | * wgGallery module for xoops |
||||||||||
| 17 | * |
||||||||||
| 18 | * @copyright module for xoops |
||||||||||
| 19 | * @license GPL 2.0 or later |
||||||||||
| 20 | * @package wggallery |
||||||||||
| 21 | * @since 1.0 |
||||||||||
| 22 | * @min_xoops 2.5.9 |
||||||||||
| 23 | * @author Wedega - Email:<[email protected]> - Website:<https://wedega.com> |
||||||||||
| 24 | */ |
||||||||||
| 25 | class Resizer |
||||||||||
| 26 | { |
||||||||||
| 27 | public $sourceFile = ''; |
||||||||||
| 28 | public $endFile = ''; |
||||||||||
| 29 | public $maxWidth = 0; |
||||||||||
| 30 | public $maxHeight = 0; |
||||||||||
| 31 | public $imageMimetype = ''; |
||||||||||
| 32 | public $jpgQuality = 90; |
||||||||||
| 33 | public $mergeType = 0; |
||||||||||
| 34 | public $mergePos = 0; |
||||||||||
| 35 | |||||||||||
| 36 | /** |
||||||||||
| 37 | * resize image if size exceed given width/height |
||||||||||
| 38 | * @return string|bool |
||||||||||
| 39 | */ |
||||||||||
| 40 | public function resizeImage() |
||||||||||
| 41 | { |
||||||||||
| 42 | // check file extension |
||||||||||
| 43 | switch ($this->imageMimetype) { |
||||||||||
| 44 | case 'image/png': |
||||||||||
| 45 | $img = imagecreatefrompng($this->sourceFile); |
||||||||||
| 46 | break; |
||||||||||
| 47 | case 'image/jpeg': |
||||||||||
| 48 | $img = imagecreatefromjpeg($this->sourceFile); |
||||||||||
| 49 | break; |
||||||||||
| 50 | case 'image/gif': |
||||||||||
| 51 | $img = imagecreatefromgif($this->sourceFile); |
||||||||||
| 52 | break; |
||||||||||
| 53 | default: |
||||||||||
| 54 | return 'Unsupported format'; |
||||||||||
| 55 | } |
||||||||||
| 56 | |||||||||||
| 57 | $width = imagesx($img); |
||||||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||||||
| 58 | $height = imagesy($img); |
||||||||||
|
0 ignored issues
–
show
It seems like
$img can also be of type false; however, parameter $image of imagesy() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||||||
| 59 | $new_width = 0; |
||||||||||
| 60 | $new_height = 0; |
||||||||||
| 61 | |||||||||||
| 62 | if ($width > $this->maxWidth || $height > $this->maxHeight) { |
||||||||||
| 63 | // recalc image size based on this->maxWidth/this->maxHeight |
||||||||||
| 64 | if ($width > $height) { |
||||||||||
| 65 | if ($width < $this->maxWidth) { |
||||||||||
| 66 | $new_width = $width; |
||||||||||
| 67 | } else { |
||||||||||
| 68 | $new_width = $this->maxWidth; |
||||||||||
| 69 | $divisor = $width / $new_width; |
||||||||||
| 70 | $new_height = floor($height / $divisor); |
||||||||||
| 71 | } |
||||||||||
| 72 | } elseif ($height < $this->maxHeight) { |
||||||||||
| 73 | $new_height = $height; |
||||||||||
| 74 | } else { |
||||||||||
| 75 | $new_height = $this->maxHeight; |
||||||||||
| 76 | $divisor = $height / $new_height; |
||||||||||
| 77 | $new_width = floor($width / $divisor); |
||||||||||
| 78 | } |
||||||||||
| 79 | |||||||||||
| 80 | // Create a new temporary image. |
||||||||||
| 81 | $tmpimg = imagecreatetruecolor($new_width, $new_height); |
||||||||||
|
0 ignored issues
–
show
It seems like
$new_height can also be of type double; however, parameter $height of imagecreatetruecolor() does only seem to accept integer, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
It seems like
$new_width can also be of type double; however, parameter $width of imagecreatetruecolor() does only seem to accept integer, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||||||
| 82 | imagealphablending($tmpimg, false); |
||||||||||
|
0 ignored issues
–
show
It seems like
$tmpimg can also be of type false; however, parameter $image of imagealphablending() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||||||
| 83 | imagesavealpha($tmpimg, true); |
||||||||||
|
0 ignored issues
–
show
It seems like
$tmpimg can also be of type false; however, parameter $image of imagesavealpha() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||||||
| 84 | |||||||||||
| 85 | // Copy and resize old image into new image. |
||||||||||
| 86 | imagecopyresampled($tmpimg, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height); |
||||||||||
|
0 ignored issues
–
show
It seems like
$new_width can also be of type double; however, parameter $dst_w of imagecopyresampled() does only seem to accept integer, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
It seems like
$img can also be of type false; however, parameter $src_image of imagecopyresampled() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
It seems like
$new_height can also be of type double; however, parameter $dst_h of imagecopyresampled() does only seem to accept integer, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
It seems like
$tmpimg can also be of type false; however, parameter $dst_image of imagecopyresampled() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||||||
| 87 | |||||||||||
| 88 | unlink($this->endFile); |
||||||||||
| 89 | //compressing the file |
||||||||||
| 90 | switch ($this->imageMimetype) { |
||||||||||
| 91 | case 'image/png': |
||||||||||
| 92 | imagepng($tmpimg, $this->endFile, 0); |
||||||||||
|
0 ignored issues
–
show
It seems like
$tmpimg can also be of type false; however, parameter $image of imagepng() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||||||
| 93 | break; |
||||||||||
| 94 | case 'image/jpeg': |
||||||||||
| 95 | imagejpeg($tmpimg, $this->endFile, 100); |
||||||||||
|
0 ignored issues
–
show
It seems like
$tmpimg can also be of type false; however, parameter $image of imagejpeg() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||||||
| 96 | break; |
||||||||||
| 97 | case 'image/gif': |
||||||||||
| 98 | imagegif($tmpimg, $this->endFile); |
||||||||||
|
0 ignored issues
–
show
It seems like
$tmpimg can also be of type false; however, parameter $image of imagegif() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||||||
| 99 | break; |
||||||||||
| 100 | } |
||||||||||
| 101 | |||||||||||
| 102 | // release the memory |
||||||||||
| 103 | imagedestroy($tmpimg); |
||||||||||
|
0 ignored issues
–
show
It seems like
$tmpimg can also be of type false; however, parameter $image of imagedestroy() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||||||
| 104 | } else { |
||||||||||
| 105 | return 'copy'; |
||||||||||
| 106 | } |
||||||||||
| 107 | imagedestroy($img); |
||||||||||
| 108 | |||||||||||
| 109 | return true; |
||||||||||
| 110 | } |
||||||||||
| 111 | |||||||||||
| 112 | // public function resizeAndCrop($this->sourceFile, $this->imageMimetype, $this->endFile, $this->maxWidth, $this->maxHeight, $this->jpgQuality=90) |
||||||||||
| 113 | |||||||||||
| 114 | /** |
||||||||||
| 115 | * @return bool|string |
||||||||||
| 116 | */ |
||||||||||
| 117 | public function resizeAndCrop() |
||||||||||
| 118 | { |
||||||||||
| 119 | // check file extension |
||||||||||
| 120 | switch ($this->imageMimetype) { |
||||||||||
| 121 | case 'image/png': |
||||||||||
| 122 | $original = imagecreatefrompng($this->sourceFile); |
||||||||||
| 123 | break; |
||||||||||
| 124 | case 'image/jpeg': |
||||||||||
| 125 | $original = imagecreatefromjpeg($this->sourceFile); |
||||||||||
| 126 | break; |
||||||||||
| 127 | case 'image/gif': |
||||||||||
| 128 | $original = imagecreatefromgif($this->sourceFile); |
||||||||||
| 129 | break; |
||||||||||
| 130 | default: |
||||||||||
| 131 | return 'Unsupported format'; |
||||||||||
| 132 | } |
||||||||||
| 133 | |||||||||||
| 134 | if (!$original) { |
||||||||||
|
0 ignored issues
–
show
|
|||||||||||
| 135 | return false; |
||||||||||
| 136 | } |
||||||||||
| 137 | // GET ORIGINAL IMAGE DIMENSIONS |
||||||||||
| 138 | list($original_w, $original_h) = getimagesize($this->sourceFile); |
||||||||||
| 139 | |||||||||||
| 140 | // RESIZE IMAGE AND PRESERVE PROPORTIONS |
||||||||||
| 141 | $max_width_resize = $this->maxWidth; |
||||||||||
| 142 | $max_height_resize = $this->maxHeight; |
||||||||||
| 143 | if ($original_w > $original_h) { |
||||||||||
| 144 | $max_height_ratio = $this->maxHeight / $original_h; |
||||||||||
| 145 | $max_width_resize = (int)round($original_w * $max_height_ratio); |
||||||||||
| 146 | } else { |
||||||||||
| 147 | $max_width_ratio = $this->maxWidth / $original_w; |
||||||||||
| 148 | $max_height_resize = (int)round($original_h * $max_width_ratio); |
||||||||||
| 149 | } |
||||||||||
| 150 | if ($max_width_resize < $this->maxWidth) { |
||||||||||
| 151 | $max_height_ratio = $this->maxWidth / $max_width_resize; |
||||||||||
| 152 | $max_height_resize = (int)round($this->maxHeight * $max_height_ratio); |
||||||||||
| 153 | $max_width_resize = $this->maxWidth; |
||||||||||
| 154 | } |
||||||||||
| 155 | |||||||||||
| 156 | // CREATE THE PROPORTIONAL IMAGE RESOURCE |
||||||||||
| 157 | $thumb = imagecreatetruecolor($max_width_resize, $max_height_resize); |
||||||||||
| 158 | if (!imagecopyresampled($thumb, $original, 0, 0, 0, 0, $max_width_resize, $max_height_resize, $original_w, $original_h)) { |
||||||||||
| 159 | return false; |
||||||||||
| 160 | } |
||||||||||
| 161 | // CREATE THE CENTERED CROPPED IMAGE TO THE SPECIFIED DIMENSIONS |
||||||||||
| 162 | $final = imagecreatetruecolor($this->maxWidth, $this->maxHeight); |
||||||||||
| 163 | |||||||||||
| 164 | $max_width_offset = 0; |
||||||||||
| 165 | $max_height_offset = 0; |
||||||||||
| 166 | if ($this->maxWidth < $max_width_resize) { |
||||||||||
| 167 | $max_width_offset = (int)round(($max_width_resize - $this->maxWidth) / 2); |
||||||||||
| 168 | } else { |
||||||||||
| 169 | $max_height_offset = (int)round(($max_height_resize - $this->maxHeight) / 2); |
||||||||||
| 170 | } |
||||||||||
| 171 | |||||||||||
| 172 | if (!imagecopy($final, $thumb, 0, 0, $max_width_offset, $max_height_offset, $max_width_resize, $max_height_resize)) { |
||||||||||
| 173 | return false; |
||||||||||
| 174 | } |
||||||||||
| 175 | // STORE THE FINAL IMAGE - WILL OVERWRITE $this->endFile |
||||||||||
| 176 | if (!imagejpeg($final, $this->endFile, $this->jpgQuality)) { |
||||||||||
| 177 | return false; |
||||||||||
| 178 | } |
||||||||||
| 179 | |||||||||||
| 180 | return true; |
||||||||||
| 181 | } |
||||||||||
| 182 | |||||||||||
| 183 | // public function mergeImage($this->sourceFile, $this->endFile, $this->mergePos, $this->mergeType) |
||||||||||
| 184 | public function mergeImage() |
||||||||||
| 185 | { |
||||||||||
| 186 | $dest = imagecreatefromjpeg($this->endFile); |
||||||||||
| 187 | $src = imagecreatefromjpeg($this->sourceFile); |
||||||||||
| 188 | if (4 == $this->mergeType) { |
||||||||||
| 189 | $imgWidth = (int)round($this->maxWidth / 2 - 1); |
||||||||||
| 190 | $imgHeight = (int)round($this->maxHeight / 2 - 1); |
||||||||||
| 191 | $posCol2 = (int)round($this->maxWidth / 2 + 1); |
||||||||||
| 192 | $posRow2 = (int)round($this->maxHeight / 2 + 1); |
||||||||||
| 193 | switch ($this->mergePos) { |
||||||||||
| 194 | case 1: |
||||||||||
| 195 | imagecopy($dest, $src, 0, 0, 0, 0, $imgWidth, $imgHeight); //top left |
||||||||||
|
0 ignored issues
–
show
It seems like
$src can also be of type false; however, parameter $src_im of imagecopy() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
It seems like
$dest can also be of type false; however, parameter $dst_im of imagecopy() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||||||
| 196 | break; |
||||||||||
| 197 | case 2: |
||||||||||
| 198 | imagecopy($dest, $src, $posCol2, 0, 0, 0, $imgWidth, $imgHeight); //top right |
||||||||||
| 199 | break; |
||||||||||
| 200 | case 3: |
||||||||||
| 201 | imagecopy($dest, $src, 0, $posRow2, 0, 0, $imgWidth, $imgHeight); //bottom left |
||||||||||
| 202 | break; |
||||||||||
| 203 | case 4: |
||||||||||
| 204 | imagecopy($dest, $src, $posCol2, $posRow2, 0, 0, $imgWidth, $imgHeight); //bottom right |
||||||||||
| 205 | break; |
||||||||||
| 206 | } |
||||||||||
| 207 | } |
||||||||||
| 208 | if (6 == $this->mergeType) { |
||||||||||
| 209 | $imgWidth = (int)round($this->maxWidth / 3 - 1); |
||||||||||
| 210 | $imgHeight = (int)round($this->maxHeight / 2 - 1); |
||||||||||
| 211 | $posCol2 = (int)round($this->maxWidth / 3 + 1); |
||||||||||
| 212 | $posCol3 = $posCol2 + (int)round($this->maxWidth / 3 + 1); |
||||||||||
| 213 | $posRow2 = (int)round($this->maxHeight / 2 + 1); |
||||||||||
| 214 | |||||||||||
| 215 | switch ($this->mergePos) { |
||||||||||
| 216 | case 1: |
||||||||||
| 217 | imagecopy($dest, $src, 0, 0, 0, 0, $imgWidth, $imgHeight); //top left |
||||||||||
| 218 | break; |
||||||||||
| 219 | case 2: |
||||||||||
| 220 | imagecopy($dest, $src, $posCol2, 0, 0, 0, $imgWidth, $imgHeight); //top center |
||||||||||
| 221 | break; |
||||||||||
| 222 | case 3: |
||||||||||
| 223 | imagecopy($dest, $src, $posCol3, 0, 0, 0, $imgWidth, $imgHeight); //top right |
||||||||||
| 224 | break; |
||||||||||
| 225 | case 4: |
||||||||||
| 226 | imagecopy($dest, $src, 0, $posRow2, 0, 0, $imgWidth, $imgHeight); //bottom left |
||||||||||
| 227 | break; |
||||||||||
| 228 | case 5: |
||||||||||
| 229 | imagecopy($dest, $src, $posCol2, $posRow2, 0, 0, $imgWidth, $imgHeight); //bottom center |
||||||||||
| 230 | break; |
||||||||||
| 231 | case 6: |
||||||||||
| 232 | imagecopy($dest, $src, $posCol3, $posRow2, 0, 0, $imgWidth, $imgHeight); //bottom right |
||||||||||
| 233 | break; |
||||||||||
| 234 | } |
||||||||||
| 235 | } |
||||||||||
| 236 | imagejpeg($dest, $this->endFile); |
||||||||||
|
0 ignored issues
–
show
It seems like
$dest can also be of type false; however, parameter $image of imagejpeg() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||||||
| 237 | |||||||||||
| 238 | imagedestroy($src); |
||||||||||
|
0 ignored issues
–
show
It seems like
$src can also be of type false; however, parameter $image of imagedestroy() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||||||
| 239 | imagedestroy($dest); |
||||||||||
| 240 | } |
||||||||||
| 241 | } |
||||||||||
| 242 |