Instafilter\Image::load PHP Method

load() public static method

public static load ( $filename, $configuration = [] )
    public static function load($filename, $configuration = array())
    {
        $filename = realpath($filename);
        // create new image
        $instance = new self($configuration);
        if (file_exists($filename)) {
            // Check the extension
            $ext = $instance->check_extension($filename, false);
            if ($ext !== false) {
                $instance->image_fullpath = $filename;
                $instance->image_directory = dirname($filename);
                $instance->image_filename = basename($filename);
                $instance->image_extension = $ext;
                // here we create a temporary file that we apply our filters to
                if (empty($instance->image_temp)) {
                    do {
                        $instance->image_temp = $instance->configuration['temp_dir'] . substr($instance->configuration['temp_append'] . md5(time() * microtime()), 0, 32) . '.png';
                    } while (file_exists($instance->image_temp));
                } elseif (file_exists($instance->image_temp)) {
                    $instance->debug('Removing previous temporary image.');
                    unlink($instance->image_temp);
                }
                $instance->debug('Temp file: ' . $instance->image_temp);
                if (!file_exists($instance->configuration['temp_dir']) || !is_dir($instance->configuration['temp_dir'])) {
                    throw new \RuntimeException("The temp directory that was given does not exist.");
                } elseif (!touch($instance->configuration['temp_dir'] . $instance->configuration['temp_append'] . '_touch')) {
                    throw new \RuntimeException("Could not write in the temp directory.");
                }
                // Move the image to the temporary place
                $instance->imagick = new \Imagick($instance->image_fullpath);
                $instance->imagick->writeImage($instance->image_temp);
            } else {
                throw new \RuntimeException("The library does not support this filetype for {$filename}.");
            }
        } else {
            throw new \OutOfBoundsException("Image file {$filename} does not exist.");
        }
        return $instance;
    }