/** * Get all size variations of this Pageimage * * This is useful after a delete of an image (for example). This method can be used to track down all the child files that also need to be deleted. * * @param array $options One or more options of: * - info (bool): when true, method returns variation info arrays rather than Pageimage objects * - width (int): only variations with given width will be returned * - height (int): only variations with given height will be returned * - width>= (int): only variations with width greater than or equal to given will be returned * - height>= (int): only variations with height greater than or equal to given will be returned * - width<= (int): only variations with width less than or equal to given will be returned * - height<= (int): only variations with height less than or equal to given will be returned * - suffix (string): only variations having the given suffix will be returned * @return Pageimages|array Returns Pageimages array of Pageimage instances. Only returns regular array if $options[info] is true. * */ public function getVariations(array $options = array()) { if (!is_null($this->variations)) { return $this->variations; } $variations = new Pageimages($this->pagefiles->page); $dir = new DirectoryIterator($this->pagefiles->path); $infos = array(); foreach ($dir as $file) { if ($file->isDir() || $file->isDot()) { continue; } $info = $this->isVariation($file->getFilename()); if (!$info) { continue; } $allow = true; if (count($options)) { foreach ($options as $option => $value) { switch ($option) { case 'width': $allow = $info['width'] == $value; break; case 'width>=': $allow = $info['width'] >= $value; break; case 'width<=': $allow = $info['width'] <= $value; break; case 'height': $allow = $info['height'] == $value; break; case 'height>=': $allow = $info['height'] >= $value; break; case 'height<=': $allow = $info['height'] <= $value; break; case 'suffix': $allow = in_array($value, $info['suffix']); break; } } } if (!$allow) { continue; } if (!empty($options['info'])) { $infos[$file->getBasename()] = $info; } else { $pageimage = clone $this; $pathname = $file->getPathname(); if (DIRECTORY_SEPARATOR != '/') { $pathname = str_replace(DIRECTORY_SEPARATOR, '/', $pathname); } $pageimage->setFilename($pathname); $pageimage->setOriginal($this); $variations->add($pageimage); } } if (!empty($options['info'])) { return $infos; } else { $this->variations = $variations; return $variations; } }
/** * Get all size variations of this Pageimage as a Pageimages array of Pageimage objects. * * This is useful after a delete of an image (for example). This method can be used to track down all the child files that also need to be deleted. * * @return Pageimages * */ public function getVariations() { if (!is_null($this->variations)) { return $this->variations; } $variations = new Pageimages($this->pagefiles->page); $dir = new DirectoryIterator($this->pagefiles->path); $basename = basename($this->basename, "." . $this->ext()); foreach ($dir as $file) { if ($file->isDir() || $file->isDot()) { continue; } if (!preg_match('/^' . $basename . '\\.\\d+x\\d+\\.' . $this->ext() . '$/', $file->getFilename())) { continue; } $pageimage = clone $this; $pageimage->setFilename($file->getPathname()); $pageimage->setOriginal($this); $variations->add($pageimage); } $this->variations = $variations; return $variations; }
/** * Get all size variations of this Pageimage as a Pageimages array of Pageimage objects. * * This is useful after a delete of an image (for example). This method can be used to track down all the child files that also need to be deleted. * * @return Pageimages * */ public function getVariations() { if (!is_null($this->variations)) { return $this->variations; } $variations = new Pageimages($this->pagefiles->page); $dir = new DirectoryIterator($this->pagefiles->path); foreach ($dir as $file) { if ($file->isDir() || $file->isDot()) { continue; } if (!$this->isVariation($file->getFilename())) { continue; } $pageimage = clone $this; $pathname = $file->getPathname(); if (DIRECTORY_SEPARATOR != '/') { $pathname = str_replace(DIRECTORY_SEPARATOR, '/', $pathname); } $pageimage->setFilename($pathname); $pageimage->setOriginal($this); $variations->add($pageimage); } $this->variations = $variations; return $variations; }