/** * Add a derivative * * @param ImageMedium $image */ public function addDerivative(ImageMedium $image) { $this->derivatives[$image->url()] = $image->get('width'); }
/** * Create a new ImageMedium by scaling another ImageMedium object. * * @param ImageMedium $medium * @param int $from * @param int $to * @return Medium */ public static function scaledFromMedium($medium, $from, $to) { if (!$medium instanceof ImageMedium) { return $medium; } if ($to > $from) { return $medium; } $ratio = $to / $from; $width = (int) ($medium->get('width') * $ratio); $height = (int) ($medium->get('height') * $ratio); $basename = $medium->get('basename'); $basename = str_replace('@' . $from . 'x', '@' . $to . 'x', $basename); $debug = $medium->get('debug'); $medium->set('debug', false); $file = $medium->resize($width, $height)->path(); $medium->set('debug', $debug); $size = filesize($file); $medium = self::fromFile($file); $medium->set('size', $size); return ['file' => $medium, 'size' => $size]; }