PHPePub\Core\EPub::resolveImage PHP Method

resolveImage() protected method

Resolve an image src and determine it's target location and add it to the book.
protected resolveImage ( string $source, &$internalPath, &$internalSrc, &$isSourceExternal, string $baseDir = "", string $htmlDir = "" ) : boolean
$source string Image Source link.
$baseDir string Default is "", meaning it is pointing to the document root.
$htmlDir string The path to the parent HTML file's directory from the root of the archive.
return boolean
    protected function resolveImage($source, &$internalPath, &$internalSrc, &$isSourceExternal, $baseDir = "", $htmlDir = "")
    {
        if ($this->isFinalized) {
            return false;
        }
        $imageData = null;
        if (preg_match('#^(http|ftp)s?://#i', $source) == 1) {
            $urlinfo = parse_url($source);
            if (strpos($urlinfo['path'], $baseDir . "/") !== false) {
                $internalSrc = FileHelper::sanitizeFileName(urldecode(substr($urlinfo['path'], strpos($urlinfo['path'], $baseDir . "/") + strlen($baseDir) + 1)));
            }
            $internalPath = $urlinfo["scheme"] . "/" . $urlinfo["host"] . "/" . pathinfo($urlinfo["path"], PATHINFO_DIRNAME);
            $isSourceExternal = true;
            $imageData = ImageHelper::getImage($this, $source);
        } else {
            if (strpos($source, "/") === 0) {
                $internalPath = pathinfo($source, PATHINFO_DIRNAME);
                $path = $source;
                if (!file_exists($path)) {
                    $path = $this->docRoot . $path;
                }
                $imageData = ImageHelper::getImage($this, $path);
            } else {
                $internalPath = $htmlDir . "/" . preg_replace('#^[/\\.]+#', '', pathinfo($source, PATHINFO_DIRNAME));
                $path = $baseDir . "/" . $source;
                if (!file_exists($path)) {
                    $path = $this->docRoot . $path;
                }
                $imageData = ImageHelper::getImage($this, $path);
            }
        }
        if ($imageData !== false) {
            $iSrcInfo = pathinfo($internalSrc);
            if (!empty($imageData['ext']) && (!isset($iSrcInfo['extension']) || $imageData['ext'] != $iSrcInfo['extension'])) {
                $internalSrc = $iSrcInfo['filename'] . "." . $imageData['ext'];
            }
            $internalPath = RelativePath::getRelativePath("images/" . $internalPath . "/" . $internalSrc);
            if (!array_key_exists($internalPath, $this->fileList)) {
                $this->addFile($internalPath, "i_" . $internalSrc, $imageData['image'], $imageData['mime']);
                $this->fileList[$internalPath] = $source;
            }
            return true;
        }
        return false;
    }