/** * Save loaded image data to the given file name. * @param string $name Full path to the image file. * @param integer $type PHP image type constant specifying the type of image to create in that file. */ public function save_to_file($name, $type = null) { if ($this->loaded() && !isset($type)) { $type = $this->properties->php_type; } $this->assert($this->saveable_to($type), 'Saving images to type [' . $this->properties->mime_type . '/' . $this->properties->php_type . '] is not supported.', 'save_to_file', 'IMAGE'); $url = new FILE_URL($name); $url->ensure_path_exists(); if (!isset($type)) { $type = $this->properties->php_type; } $opts = global_file_options(); switch ($type) { case Image_type_GIF: imagegif($this->_data, $name); chmod($name, $opts->default_access_mode); case Image_type_JPG: imagejpeg($this->_data, $name); chmod($name, $opts->default_access_mode); break; case Image_type_PNG: imagepng($this->_data, $name); chmod($name, $opts->default_access_mode); break; default: $this->raise('saveable_to() claimed for (' . $this->properties->mime_type . '/' . $this->properties->php_type . ')', 'save_from_file', 'IMAGE'); } }