protected function processChapterImages(&$xmlDoc, $externalReferences = EPub::EXTERNAL_REF_ADD, $baseDir = "", $htmlDir = "", $backPath = "")
{
if ($this->isFinalized || $externalReferences === EPub::EXTERNAL_REF_IGNORE) {
return false;
}
// process img tags.
$postProcDomElememts = array();
$images = $xmlDoc->getElementsByTagName("img");
$itemCount = $images->length;
for ($idx = 0; $idx < $itemCount; $idx++) {
/** @var $img \DOMElement */
$img = $images->item($idx);
if ($externalReferences === EPub::EXTERNAL_REF_REMOVE_IMAGES) {
$postProcDomElememts[] = $img;
} else {
if ($externalReferences === EPub::EXTERNAL_REF_REPLACE_IMAGES) {
$altNode = $img->attributes->getNamedItem("alt");
$alt = "image";
if ($altNode !== null && strlen($altNode->nodeValue) > 0) {
$alt = $altNode->nodeValue;
}
$postProcDomElememts[] = array($img, StringHelper::createDomFragment($xmlDoc, "<em>[" . $alt . "]</em>"));
} else {
$source = $img->attributes->getNamedItem("src")->nodeValue;
$parsedSource = parse_url($source);
$internalSrc = FileHelper::sanitizeFileName(urldecode(pathinfo($parsedSource['path'], PATHINFO_BASENAME)));
$internalPath = "";
$isSourceExternal = false;
if ($this->resolveImage($source, $internalPath, $internalSrc, $isSourceExternal, $baseDir, $htmlDir)) {
$img->setAttribute("src", $backPath . $internalPath);
} else {
if ($isSourceExternal) {
$postProcDomElememts[] = $img;
// External image is missing
}
}
// else do nothing, if the image is local, and missing, assume it's been generated.
}
}
}
foreach ($postProcDomElememts as $target) {
if (is_array($target)) {
$target[0]->parentNode->replaceChild($target[1], $target[0]);
} else {
$target->parentNode->removeChild($target);
}
}
return true;
}