GdThumb::save PHP Méthode

save() public méthode

This function will make sure the target directory is writeable, and then save the image. If the target directory is not writeable, the function will try to correct the permissions (if allowed, this is set as an option ($this->options['correctPermissions']). If the target cannot be made writeable, then a RuntimeException is thrown. TODO: Create additional paramter for color matte when saving images with alpha to non-alpha formats (i.e. PNG => JPG)
public save ( string $fileName, string $format = null ) : GdThumb
$fileName string The full path and filename of the image to save
$format string The format to save the image in (optional, must be one of [GIF,JPG,PNG]
Résultat GdThumb
    public function save($fileName, $format = null)
    {
        $validFormats = array('GIF', 'JPG', 'PNG');
        $format = $format !== null ? strtoupper($format) : $this->format;
        if (!in_array($format, $validFormats)) {
            throw new InvalidArgumentException('Invalid format type specified in save function: ' . $format);
        }
        // make sure the directory is writeable
        if (!is_writable(dirname($fileName))) {
            // try to correct the permissions
            if ($this->options['correctPermissions'] === true) {
                @chmod(dirname($fileName), 0777);
                // throw an exception if not writeable
                if (!is_writable(dirname($fileName))) {
                    throw new RuntimeException('File is not writeable, and could not correct permissions: ' . $fileName);
                }
            } else {
                throw new RuntimeException('File not writeable: ' . $fileName);
            }
        }
        switch ($format) {
            case 'GIF':
                imagegif($this->oldImage, $fileName);
                break;
            case 'JPG':
                imagejpeg($this->oldImage, $fileName, $this->options['jpegQuality']);
                break;
            case 'PNG':
                imagepng($this->oldImage, $fileName);
                break;
        }
        return $this;
    }

Usage Example

Exemple #1
0
 protected function _writeResized(GdThumb $resized, $type = null)
 {
     $resized->save($this->getOutputPath(), $type);
     return $this->getOutputPath();
 }
All Usage Examples Of GdThumb::save