/** * Extract values from model * * @param ImageModel $object * @return array */ public function extract($object) { return ['name' => $object->getFileName(), 'type' => $object->getType(), 'size' => $object->getSize(), 'tmp_name' => $object->getTempName(), 'error' => $object->getError(), 'size' => [0 => $object->getWidth(), 1 => $object->getHeight(), 2 => $object->getMimeType()]]; }
/** * @param ImageModel $model * @return ImageModel * @throws UthandoFileManagerException */ public function resizeImage(ImageModel $model) : ImageModel { $options = $this->getOptions(); $image = $model->getTempName(); $oldX = $model->getWidth(); $oldY = $model->getHeight(); switch ($model->getMimeType()) { case IMAGETYPE_JPEG: $imageIn = imageCreateFromJpeg($image); break; case IMAGETYPE_PNG: $imageIn = imageCreateFromPng($image); break; case IMAGETYPE_GIF: $imageIn = imageCreateFromGif($image); break; default: throw new UthandoFileManagerException($this->error(self::MIME_NOT_SUPPORTED, $model->getMimeType())); } if ($model->getWidth() > $options->getMaxWidth()) { $model->setHeight(round($options->getMaxWidth() * $model->getHeight() / $model->getWidth())); $model->setWidth($options->getMaxWidth()); } if ($model->getHeight() > $options->getMaxHeight()) { $model->setWidth(round($model->getWidth() * $options->getMaxHeight() / $model->getHeight())); $model->setHeight($options->getMaxHeight()); } $imageOut = imageCreateTrueColor($model->getWidth(), $model->getHeight()); imageCopyResampled($imageOut, $imageIn, 0, 0, 0, 0, $model->getWidth(), $model->getHeight(), $oldX, $oldY); switch ($model->getMimeType()) { case IMAGETYPE_JPEG: imageJpeg($imageOut, $image); break; case IMAGETYPE_PNG: imagePng($imageOut, $image); break; case IMAGETYPE_GIF: imageGif($imageOut, $image); break; } imageDestroy($imageIn); imageDestroy($imageOut); return $model; }