public function check() { if (!$this->_data && !$this->uploadedFile && $this->required) { $this->postError('notSelected', self::$errorCodes['notSelected']); return; } if ($this->uploadedFile) { if ($this->maxFilesize && $this->uploadedFile->size > $this->maxFilesize) { $filesize = round($this->maxFilesize / 1024 / 1024 * 10) / 10; $this->postError('invalidFilesize', self::$errorCodes['invalidFilesize'], array('%size%' => $filesize)); return; } $image = ImageTools::checkFile($this->uploadedFile->file, $this->uploadedFile->name); if (!$image->success) { $this->postError('invalidImage', self::$errorCodes['invalidImage']); return; } if ($this->minWidth || $this->maxWidth) { $sizeX = imagesx($image->image); $sizeY = imagesy($image->image); if ($this->minWidth && ($sizeX < $this->minWidth || $sizeY < $this->minHeight)) { $this->postError('tooSmall', self::$errorCodes['tooSmall'], array('%width%' => $this->minWidth, '%height%' => $this->minHeight)); } elseif ($this->maxWidth && ($sizeX > $this->maxWidth || $sizeY > $this->maxHeight)) { $this->postError('tooLarge', self::$errorCodes['tooLarge'], array('%width%' => $this->maxWidth, '%height%' => $this->maxHeight)); } } $this->_image = $image->image; } }
public function load(Job $job) { $excludeFilters = $job->configuration->get('excludes', null); $includeFilters = $job->configuration->get('includes', null); /** @var Sprite[] $loadSprites */ $loadSprites = []; foreach ($this->folders as $folder) { $files = FileTools::listDirectory($folder, false, true); foreach ($files as $file) { $originalSpriteName = pathinfo(str_replace('/', '-', $file), PATHINFO_FILENAME); $filteredSpriteName = preg_replace('/\\{[^\\}]+\\}/', '', $originalSpriteName); // Strip {tags} $included = true; if ($excludeFilters !== null) { $included = !Tools::matches($excludeFilters, $originalSpriteName) && !Tools::matches($excludeFilters, $filteredSpriteName); } elseif ($includeFilters !== null) { $included = false; } if (!$included && $includeFilters !== null) { $included = Tools::matches($includeFilters, $originalSpriteName) || Tools::matches($includeFilters, $filteredSpriteName); } if (!$included) { continue; } $sprite = new Sprite(); $sprite->originalName = $sprite->name = $originalSpriteName; $sprite->name = $filteredSpriteName; $sprite->path = $folder . $file; $loadSprites[$sprite->name] = $sprite; } } foreach ($loadSprites as $sprite) { $sprite->configuration->extend($job->configuration->configuration); $this->extendSpriteSettings($job, $sprite); if (!$sprite->configuration->getBool('enabled', true)) { continue; } $image = ImageTools::checkFile($sprite->path); if ($image->success) { $sprite->image = $image->image; $sprite->calculateDimensions(); $job->sprites[$sprite->name] = $sprite; } } }