1*92a8473aSAndreas Gohr<?php /** @noinspection PhpComposerExtensionStubsInspection */ 2*92a8473aSAndreas Gohr 3*92a8473aSAndreas Gohr 4*92a8473aSAndreas Gohrnamespace splitbrain\slika; 5*92a8473aSAndreas Gohr 6*92a8473aSAndreas Gohr 7*92a8473aSAndreas Gohrclass GdAdapter extends Adapter 8*92a8473aSAndreas Gohr{ 9*92a8473aSAndreas Gohr /** @var resource libGD image */ 10*92a8473aSAndreas Gohr protected $image; 11*92a8473aSAndreas Gohr /** @var int width of the current image */ 12*92a8473aSAndreas Gohr protected $width = 0; 13*92a8473aSAndreas Gohr /** @var int height of the current image */ 14*92a8473aSAndreas Gohr protected $height = 0; 15*92a8473aSAndreas Gohr /** @var string the extension of the file we're working with */ 16*92a8473aSAndreas Gohr protected $extension; 17*92a8473aSAndreas Gohr 18*92a8473aSAndreas Gohr 19*92a8473aSAndreas Gohr /** @inheritDoc */ 20*92a8473aSAndreas Gohr public function __construct($imagepath, $options = []) 21*92a8473aSAndreas Gohr { 22*92a8473aSAndreas Gohr parent::__construct($imagepath, $options); 23*92a8473aSAndreas Gohr $this->image = $this->loadImage($imagepath); 24*92a8473aSAndreas Gohr } 25*92a8473aSAndreas Gohr 26*92a8473aSAndreas Gohr /** 27*92a8473aSAndreas Gohr * Clean up 28*92a8473aSAndreas Gohr */ 29*92a8473aSAndreas Gohr public function __destruct() 30*92a8473aSAndreas Gohr { 31*92a8473aSAndreas Gohr if (is_resource($this->image)) { 32*92a8473aSAndreas Gohr imagedestroy($this->image); 33*92a8473aSAndreas Gohr } 34*92a8473aSAndreas Gohr } 35*92a8473aSAndreas Gohr 36*92a8473aSAndreas Gohr /** @inheritDoc 37*92a8473aSAndreas Gohr * @throws Exception 38*92a8473aSAndreas Gohr * @link https://gist.github.com/EionRobb/8e0c76178522bc963c75caa6a77d3d37#file-imagecreatefromstring_autorotate-php-L15 39*92a8473aSAndreas Gohr */ 40*92a8473aSAndreas Gohr public function autorotate() 41*92a8473aSAndreas Gohr { 42*92a8473aSAndreas Gohr if ($this->extension !== 'jpeg') { 43*92a8473aSAndreas Gohr return $this; 44*92a8473aSAndreas Gohr } 45*92a8473aSAndreas Gohr 46*92a8473aSAndreas Gohr $orientation = 1; 47*92a8473aSAndreas Gohr 48*92a8473aSAndreas Gohr if (function_exists('exif_read_data')) { 49*92a8473aSAndreas Gohr // use PHP's exif capablities 50*92a8473aSAndreas Gohr $exif = exif_read_data($this->imagepath); 51*92a8473aSAndreas Gohr if (!empty($exif['Orientation'])) { 52*92a8473aSAndreas Gohr $orientation = $exif['Orientation']; 53*92a8473aSAndreas Gohr } 54*92a8473aSAndreas Gohr } else { 55*92a8473aSAndreas Gohr // grep the exif info from the raw contents 56*92a8473aSAndreas Gohr // we read only the first 70k bytes 57*92a8473aSAndreas Gohr $data = file_get_contents($this->imagepath, false, null, 0, 70000); 58*92a8473aSAndreas Gohr if (preg_match('@\x12\x01\x03\x00\x01\x00\x00\x00(.)\x00\x00\x00@', $data, $matches)) { 59*92a8473aSAndreas Gohr // Little endian EXIF 60*92a8473aSAndreas Gohr $orientation = ord($matches[1]); 61*92a8473aSAndreas Gohr } else if (preg_match('@\x01\x12\x00\x03\x00\x00\x00\x01\x00(.)\x00\x00@', $data, $matches)) { 62*92a8473aSAndreas Gohr // Big endian EXIF 63*92a8473aSAndreas Gohr $orientation = ord($matches[1]); 64*92a8473aSAndreas Gohr } 65*92a8473aSAndreas Gohr } 66*92a8473aSAndreas Gohr 67*92a8473aSAndreas Gohr return $this->rotate($orientation); 68*92a8473aSAndreas Gohr } 69*92a8473aSAndreas Gohr 70*92a8473aSAndreas Gohr /** 71*92a8473aSAndreas Gohr * @inheritDoc 72*92a8473aSAndreas Gohr * @throws Exception 73*92a8473aSAndreas Gohr */ 74*92a8473aSAndreas Gohr public function rotate($orientation) 75*92a8473aSAndreas Gohr { 76*92a8473aSAndreas Gohr $orientation = (int)$orientation; 77*92a8473aSAndreas Gohr if ($orientation < 0 || $orientation > 8) { 78*92a8473aSAndreas Gohr throw new Exception('Unknown rotation given'); 79*92a8473aSAndreas Gohr } 80*92a8473aSAndreas Gohr 81*92a8473aSAndreas Gohr if ($orientation <= 1) { 82*92a8473aSAndreas Gohr // no rotation wanted 83*92a8473aSAndreas Gohr return $this; 84*92a8473aSAndreas Gohr } 85*92a8473aSAndreas Gohr 86*92a8473aSAndreas Gohr // fill color 87*92a8473aSAndreas Gohr $transparency = imagecolorallocatealpha($this->image, 0, 0, 0, 127); 88*92a8473aSAndreas Gohr 89*92a8473aSAndreas Gohr // rotate 90*92a8473aSAndreas Gohr if (in_array($orientation, [3, 4])) { 91*92a8473aSAndreas Gohr $image = imagerotate($this->image, 180, $transparency, 1); 92*92a8473aSAndreas Gohr } 93*92a8473aSAndreas Gohr if (in_array($orientation, [5, 6])) { 94*92a8473aSAndreas Gohr $image = imagerotate($this->image, -90, $transparency, 1); 95*92a8473aSAndreas Gohr list($this->width, $this->height) = [$this->height, $this->width]; 96*92a8473aSAndreas Gohr } elseif (in_array($orientation, [7, 8])) { 97*92a8473aSAndreas Gohr $image = imagerotate($this->image, 90, $transparency, 1); 98*92a8473aSAndreas Gohr list($this->width, $this->height) = [$this->height, $this->width]; 99*92a8473aSAndreas Gohr } 100*92a8473aSAndreas Gohr /** @var resource $image is now defined */ 101*92a8473aSAndreas Gohr 102*92a8473aSAndreas Gohr // additionally flip 103*92a8473aSAndreas Gohr if (in_array($orientation, [2, 5, 7, 4])) { 104*92a8473aSAndreas Gohr imageflip($image, IMG_FLIP_HORIZONTAL); 105*92a8473aSAndreas Gohr } 106*92a8473aSAndreas Gohr 107*92a8473aSAndreas Gohr imagedestroy($this->image); 108*92a8473aSAndreas Gohr $this->image = $image; 109*92a8473aSAndreas Gohr 110*92a8473aSAndreas Gohr //keep png alpha channel if possible 111*92a8473aSAndreas Gohr if ($this->extension == 'png' && function_exists('imagesavealpha')) { 112*92a8473aSAndreas Gohr imagealphablending($this->image, false); 113*92a8473aSAndreas Gohr imagesavealpha($this->image, true); 114*92a8473aSAndreas Gohr } 115*92a8473aSAndreas Gohr 116*92a8473aSAndreas Gohr return $this; 117*92a8473aSAndreas Gohr } 118*92a8473aSAndreas Gohr 119*92a8473aSAndreas Gohr /** 120*92a8473aSAndreas Gohr * @inheritDoc 121*92a8473aSAndreas Gohr * @throws Exception 122*92a8473aSAndreas Gohr */ 123*92a8473aSAndreas Gohr public function resize($width, $height) 124*92a8473aSAndreas Gohr { 125*92a8473aSAndreas Gohr list($width, $height) = $this->boundingBox($width, $height); 126*92a8473aSAndreas Gohr $this->resizeOperation($width, $height); 127*92a8473aSAndreas Gohr return $this; 128*92a8473aSAndreas Gohr } 129*92a8473aSAndreas Gohr 130*92a8473aSAndreas Gohr /** 131*92a8473aSAndreas Gohr * @inheritDoc 132*92a8473aSAndreas Gohr * @throws Exception 133*92a8473aSAndreas Gohr */ 134*92a8473aSAndreas Gohr public function crop($width, $height) 135*92a8473aSAndreas Gohr { 136*92a8473aSAndreas Gohr list($this->width, $this->height, $offsetX, $offsetY) = $this->cropPosition($width, $height); 137*92a8473aSAndreas Gohr $this->resizeOperation($width, $height, $offsetX, $offsetY); 138*92a8473aSAndreas Gohr return $this; 139*92a8473aSAndreas Gohr } 140*92a8473aSAndreas Gohr 141*92a8473aSAndreas Gohr /** 142*92a8473aSAndreas Gohr * @inheritDoc 143*92a8473aSAndreas Gohr * @throws Exception 144*92a8473aSAndreas Gohr */ 145*92a8473aSAndreas Gohr public function save($path, $extension = '') 146*92a8473aSAndreas Gohr { 147*92a8473aSAndreas Gohr if ($extension === 'jpg') { 148*92a8473aSAndreas Gohr $extension = 'jpeg'; 149*92a8473aSAndreas Gohr } 150*92a8473aSAndreas Gohr if ($extension === '') { 151*92a8473aSAndreas Gohr $extension = $this->extension; 152*92a8473aSAndreas Gohr } 153*92a8473aSAndreas Gohr $saver = 'image' . $extension; 154*92a8473aSAndreas Gohr if (!function_exists($saver)) { 155*92a8473aSAndreas Gohr throw new Exception('Can not save image format ' . $extension); 156*92a8473aSAndreas Gohr } 157*92a8473aSAndreas Gohr 158*92a8473aSAndreas Gohr if ($extension == 'jpeg') { 159*92a8473aSAndreas Gohr imagejpeg($this->image, $path, $this->options['quality']); 160*92a8473aSAndreas Gohr } else { 161*92a8473aSAndreas Gohr $saver($this->image, $path); 162*92a8473aSAndreas Gohr } 163*92a8473aSAndreas Gohr 164*92a8473aSAndreas Gohr imagedestroy($this->image); 165*92a8473aSAndreas Gohr } 166*92a8473aSAndreas Gohr 167*92a8473aSAndreas Gohr /** 168*92a8473aSAndreas Gohr * Initialize libGD on the given image 169*92a8473aSAndreas Gohr * 170*92a8473aSAndreas Gohr * @param string $path 171*92a8473aSAndreas Gohr * @return resource 172*92a8473aSAndreas Gohr * @throws Exception 173*92a8473aSAndreas Gohr */ 174*92a8473aSAndreas Gohr protected function loadImage($path) 175*92a8473aSAndreas Gohr { 176*92a8473aSAndreas Gohr // Figure out the file info 177*92a8473aSAndreas Gohr $info = getimagesize($path); 178*92a8473aSAndreas Gohr if ($info === false) { 179*92a8473aSAndreas Gohr throw new Exception('Failed to read image information'); 180*92a8473aSAndreas Gohr } 181*92a8473aSAndreas Gohr $this->width = $info[0]; 182*92a8473aSAndreas Gohr $this->height = $info[1]; 183*92a8473aSAndreas Gohr 184*92a8473aSAndreas Gohr // what type of image is it? 185*92a8473aSAndreas Gohr $this->extension = image_type_to_extension($info[2], false); 186*92a8473aSAndreas Gohr $creator = 'imagecreatefrom' . $this->extension; 187*92a8473aSAndreas Gohr if (!function_exists($creator)) { 188*92a8473aSAndreas Gohr throw new Exception('Can not work with image format ' . $this->extension); 189*92a8473aSAndreas Gohr } 190*92a8473aSAndreas Gohr 191*92a8473aSAndreas Gohr // create the GD instance 192*92a8473aSAndreas Gohr $image = @$creator($path); 193*92a8473aSAndreas Gohr 194*92a8473aSAndreas Gohr if ($image === false) { 195*92a8473aSAndreas Gohr throw new Exception('Failed to load image wiht libGD'); 196*92a8473aSAndreas Gohr } 197*92a8473aSAndreas Gohr 198*92a8473aSAndreas Gohr return $image; 199*92a8473aSAndreas Gohr } 200*92a8473aSAndreas Gohr 201*92a8473aSAndreas Gohr /** 202*92a8473aSAndreas Gohr * Creates a new blank image to which we can copy 203*92a8473aSAndreas Gohr * 204*92a8473aSAndreas Gohr * Tries to set up alpha/transparency stuff correctly 205*92a8473aSAndreas Gohr * 206*92a8473aSAndreas Gohr * @param int $width 207*92a8473aSAndreas Gohr * @param int $height 208*92a8473aSAndreas Gohr * @return resource 209*92a8473aSAndreas Gohr * @throws Exception 210*92a8473aSAndreas Gohr */ 211*92a8473aSAndreas Gohr protected function createImage($width, $height) 212*92a8473aSAndreas Gohr { 213*92a8473aSAndreas Gohr // create a canvas to copy to, use truecolor if possible (except for gif) 214*92a8473aSAndreas Gohr $canvas = false; 215*92a8473aSAndreas Gohr if (function_exists('imagecreatetruecolor') && $this->extension != 'gif') { 216*92a8473aSAndreas Gohr $canvas = @imagecreatetruecolor($width, $height); 217*92a8473aSAndreas Gohr } 218*92a8473aSAndreas Gohr if (!$canvas) { 219*92a8473aSAndreas Gohr $canvas = @imagecreate($width, $height); 220*92a8473aSAndreas Gohr } 221*92a8473aSAndreas Gohr if (!$canvas) { 222*92a8473aSAndreas Gohr throw new Exception('Failed to create new canvas'); 223*92a8473aSAndreas Gohr } 224*92a8473aSAndreas Gohr 225*92a8473aSAndreas Gohr //keep png alpha channel if possible 226*92a8473aSAndreas Gohr if ($this->extension == 'png' && function_exists('imagesavealpha')) { 227*92a8473aSAndreas Gohr imagealphablending($canvas, false); 228*92a8473aSAndreas Gohr imagesavealpha($canvas, true); 229*92a8473aSAndreas Gohr } 230*92a8473aSAndreas Gohr 231*92a8473aSAndreas Gohr //keep gif transparent color if possible 232*92a8473aSAndreas Gohr if ($this->extension == 'gif' && function_exists('imagefill') && function_exists('imagecolorallocate')) { 233*92a8473aSAndreas Gohr if (function_exists('imagecolorsforindex') && function_exists('imagecolortransparent')) { 234*92a8473aSAndreas Gohr $transcolorindex = @imagecolortransparent($this->image); 235*92a8473aSAndreas Gohr if ($transcolorindex >= 0) { //transparent color exists 236*92a8473aSAndreas Gohr $transcolor = @imagecolorsforindex($this->image, $transcolorindex); 237*92a8473aSAndreas Gohr $transcolorindex = @imagecolorallocate( 238*92a8473aSAndreas Gohr $canvas, 239*92a8473aSAndreas Gohr $transcolor['red'], 240*92a8473aSAndreas Gohr $transcolor['green'], 241*92a8473aSAndreas Gohr $transcolor['blue'] 242*92a8473aSAndreas Gohr ); 243*92a8473aSAndreas Gohr @imagefill($canvas, 0, 0, $transcolorindex); 244*92a8473aSAndreas Gohr @imagecolortransparent($canvas, $transcolorindex); 245*92a8473aSAndreas Gohr } else { //filling with white 246*92a8473aSAndreas Gohr $whitecolorindex = @imagecolorallocate($canvas, 255, 255, 255); 247*92a8473aSAndreas Gohr @imagefill($canvas, 0, 0, $whitecolorindex); 248*92a8473aSAndreas Gohr } 249*92a8473aSAndreas Gohr } else { //filling with white 250*92a8473aSAndreas Gohr $whitecolorindex = @imagecolorallocate($canvas, 255, 255, 255); 251*92a8473aSAndreas Gohr @imagefill($canvas, 0, 0, $whitecolorindex); 252*92a8473aSAndreas Gohr } 253*92a8473aSAndreas Gohr } 254*92a8473aSAndreas Gohr 255*92a8473aSAndreas Gohr return $canvas; 256*92a8473aSAndreas Gohr } 257*92a8473aSAndreas Gohr 258*92a8473aSAndreas Gohr /** 259*92a8473aSAndreas Gohr * Calculate new size 260*92a8473aSAndreas Gohr * 261*92a8473aSAndreas Gohr * If widht and height are given, the new size will be fit within this bounding box. 262*92a8473aSAndreas Gohr * If only one value is given the other is adjusted to match according to the aspect ratio 263*92a8473aSAndreas Gohr * 264*92a8473aSAndreas Gohr * @param int $width width of the bounding box 265*92a8473aSAndreas Gohr * @param int $height height of the bounding box 266*92a8473aSAndreas Gohr * @return array (width, height) 267*92a8473aSAndreas Gohr * @throws Exception 268*92a8473aSAndreas Gohr */ 269*92a8473aSAndreas Gohr protected function boundingBox($width, $height) 270*92a8473aSAndreas Gohr { 271*92a8473aSAndreas Gohr if ($width == 0 && $height == 0) { 272*92a8473aSAndreas Gohr throw new Exception('You can not resize to 0x0'); 273*92a8473aSAndreas Gohr } 274*92a8473aSAndreas Gohr 275*92a8473aSAndreas Gohr if (!$height) { 276*92a8473aSAndreas Gohr // adjust to match width 277*92a8473aSAndreas Gohr $height = round(($width * $this->height) / $this->width); 278*92a8473aSAndreas Gohr } else if (!$width) { 279*92a8473aSAndreas Gohr // adjust to match height 280*92a8473aSAndreas Gohr $width = round(($height * $this->width) / $this->height); 281*92a8473aSAndreas Gohr } else { 282*92a8473aSAndreas Gohr // fit into bounding box 283*92a8473aSAndreas Gohr $scale = min($width / $this->width, $height / $this->height); 284*92a8473aSAndreas Gohr $width = $this->width * $scale; 285*92a8473aSAndreas Gohr $height = $this->height * $scale; 286*92a8473aSAndreas Gohr } 287*92a8473aSAndreas Gohr 288*92a8473aSAndreas Gohr return [$width, $height]; 289*92a8473aSAndreas Gohr } 290*92a8473aSAndreas Gohr 291*92a8473aSAndreas Gohr /** 292*92a8473aSAndreas Gohr * Calculates crop position 293*92a8473aSAndreas Gohr * 294*92a8473aSAndreas Gohr * Given the wanted final size, this calculates which exact area needs to be cut 295*92a8473aSAndreas Gohr * from the original image to be then resized to the wanted dimensions. 296*92a8473aSAndreas Gohr * 297*92a8473aSAndreas Gohr * @param int $width 298*92a8473aSAndreas Gohr * @param int $height 299*92a8473aSAndreas Gohr * @return array (cropWidth, cropHeight, offsetX, offsetY) 300*92a8473aSAndreas Gohr * @throws Exception 301*92a8473aSAndreas Gohr */ 302*92a8473aSAndreas Gohr protected function cropPosition($width, $height) 303*92a8473aSAndreas Gohr { 304*92a8473aSAndreas Gohr if ($width == 0 && $height == 0) { 305*92a8473aSAndreas Gohr throw new Exception('You can not crop to 0x0'); 306*92a8473aSAndreas Gohr } 307*92a8473aSAndreas Gohr 308*92a8473aSAndreas Gohr if (!$height) { 309*92a8473aSAndreas Gohr $height = $width; 310*92a8473aSAndreas Gohr } 311*92a8473aSAndreas Gohr 312*92a8473aSAndreas Gohr if (!$width) { 313*92a8473aSAndreas Gohr $width = $height; 314*92a8473aSAndreas Gohr } 315*92a8473aSAndreas Gohr 316*92a8473aSAndreas Gohr // calculate ratios 317*92a8473aSAndreas Gohr $oldRatio = $this->width / $this->height; 318*92a8473aSAndreas Gohr $newRatio = $width / $height; 319*92a8473aSAndreas Gohr 320*92a8473aSAndreas Gohr // calulate new size 321*92a8473aSAndreas Gohr if ($newRatio >= 1) { 322*92a8473aSAndreas Gohr if ($newRatio > $oldRatio) { 323*92a8473aSAndreas Gohr $cropWidth = $this->width; 324*92a8473aSAndreas Gohr $cropHeight = (int)($this->width / $newRatio); 325*92a8473aSAndreas Gohr } else { 326*92a8473aSAndreas Gohr $cropWidth = (int)($this->height * $newRatio); 327*92a8473aSAndreas Gohr $cropHeight = $this->height; 328*92a8473aSAndreas Gohr } 329*92a8473aSAndreas Gohr } else { 330*92a8473aSAndreas Gohr if ($newRatio < $oldRatio) { 331*92a8473aSAndreas Gohr $cropWidth = (int)($this->height * $newRatio); 332*92a8473aSAndreas Gohr $cropHeight = $this->height; 333*92a8473aSAndreas Gohr } else { 334*92a8473aSAndreas Gohr $cropWidth = $this->width; 335*92a8473aSAndreas Gohr $cropHeight = (int)($this->width / $newRatio); 336*92a8473aSAndreas Gohr } 337*92a8473aSAndreas Gohr } 338*92a8473aSAndreas Gohr 339*92a8473aSAndreas Gohr // calculate crop offset 340*92a8473aSAndreas Gohr $offsetX = (int)(($this->width - $cropWidth) / 2); 341*92a8473aSAndreas Gohr $offsetY = (int)(($this->height - $cropHeight) / 2); 342*92a8473aSAndreas Gohr 343*92a8473aSAndreas Gohr return [$cropWidth, $cropHeight, $offsetX, $offsetY]; 344*92a8473aSAndreas Gohr } 345*92a8473aSAndreas Gohr 346*92a8473aSAndreas Gohr /** 347*92a8473aSAndreas Gohr * resize or crop images using PHP's libGD support 348*92a8473aSAndreas Gohr * 349*92a8473aSAndreas Gohr * @param int $toWidth desired width 350*92a8473aSAndreas Gohr * @param int $toHeight desired height 351*92a8473aSAndreas Gohr * @param int $offsetX offset of crop centre 352*92a8473aSAndreas Gohr * @param int $offsetY offset of crop centre 353*92a8473aSAndreas Gohr * @throws Exception 354*92a8473aSAndreas Gohr */ 355*92a8473aSAndreas Gohr protected function resizeOperation($toWidth, $toHeight, $offsetX = 0, $offsetY = 0) 356*92a8473aSAndreas Gohr { 357*92a8473aSAndreas Gohr $newimg = $this->createImage($toWidth, $toHeight); 358*92a8473aSAndreas Gohr 359*92a8473aSAndreas Gohr //try resampling first, fall back to resizing 360*92a8473aSAndreas Gohr if ( 361*92a8473aSAndreas Gohr !function_exists('imagecopyresampled') || 362*92a8473aSAndreas Gohr !@imagecopyresampled( 363*92a8473aSAndreas Gohr $newimg, 364*92a8473aSAndreas Gohr $this->image, 365*92a8473aSAndreas Gohr 0, 366*92a8473aSAndreas Gohr 0, 367*92a8473aSAndreas Gohr $offsetX, 368*92a8473aSAndreas Gohr $offsetY, 369*92a8473aSAndreas Gohr $toWidth, 370*92a8473aSAndreas Gohr $toHeight, 371*92a8473aSAndreas Gohr $this->width, 372*92a8473aSAndreas Gohr $this->height 373*92a8473aSAndreas Gohr ) 374*92a8473aSAndreas Gohr ) { 375*92a8473aSAndreas Gohr imagecopyresized( 376*92a8473aSAndreas Gohr $newimg, 377*92a8473aSAndreas Gohr $this->image, 378*92a8473aSAndreas Gohr 0, 379*92a8473aSAndreas Gohr 0, 380*92a8473aSAndreas Gohr $offsetX, 381*92a8473aSAndreas Gohr $offsetY, 382*92a8473aSAndreas Gohr $toWidth, 383*92a8473aSAndreas Gohr $toHeight, 384*92a8473aSAndreas Gohr $this->width, 385*92a8473aSAndreas Gohr $this->height 386*92a8473aSAndreas Gohr ); 387*92a8473aSAndreas Gohr } 388*92a8473aSAndreas Gohr 389*92a8473aSAndreas Gohr // destroy original GD image ressource and replace with new one 390*92a8473aSAndreas Gohr imagedestroy($this->image); 391*92a8473aSAndreas Gohr $this->image = $newimg; 392*92a8473aSAndreas Gohr $this->width = $toWidth; 393*92a8473aSAndreas Gohr $this->height = $toHeight; 394*92a8473aSAndreas Gohr } 395*92a8473aSAndreas Gohr 396*92a8473aSAndreas Gohr} 397