/** * Register image element. * * @param IdmlImage $idmlImage containing mediaFilename and optionally containing imageContent (from parsed CDATA). * @param IdmlElement $idmlContainer is the wrapper of the image, which is needed for cropping operations. */ public function registerImage(IdmlImage $idmlImage, $idmlContainer) { $tmpPath = null; $containersAllowed = array('IdmlRectangle', 'IdmlPolygon'); // If the image data has come from embedded CDATA . . . if ($idmlImage->embeddedImage && strlen($idmlImage->imageContent) > 0) { $tmpPath = $this->FileManager->getTmpPath(); $registerFilename = $this->createImageFromCdata($idmlImage, $tmpPath); } else { // assemble the filename path, within the S3 bucket, and verify that it exists $registerFilename = $this->getImageFile($idmlImage); if ($registerFilename == null) { $idmlImage->mediaFilename .= " [image not found]"; return; } } // Crop the picture if asked to if ($idmlContainer != null && in_array(get_class($idmlContainer), $containersAllowed)) { if (MediaManager::isVectorImage($registerFilename)) { // skip for now, because cropping .ai is crashing IMagick } else { $this->cropImage($idmlImage, $idmlContainer, $registerFilename); } } // Does this image need to be converted? if (MediaManager::isConvertableImage($registerFilename)) { $idmlImage->mediaFilename = $this->processor->convertUnsupportedImageType($registerFilename); } }
/** * Primary processing routine for the source */ private function processBook() { // Get Media manager and preset page parameters $mediaManager = new MediaManager($this->bookId); $pageCount = count($this->sourceFiles) + count($this->sourceAssets); $pageNumber = 1; // Prepare the progress $this->progress->startProgress($pageCount * 2); $this->updatePageCount(0); $bookSizeFound = false; // Loop through source files foreach ($this->sourceFiles as $source) { CakeLog::debug('[ImageProcessor::processBook] processing source file ' . $source); // Get book size if (!$bookSizeFound) { $bookWidth = 0; $bookHeight = 0; $this->getBookSizeImage($source, $bookWidth, $bookHeight); CakeLog::debug('[ImageProcessor::processBook] Book dimensions set to ' . $bookWidth . ' x ' . $bookHeight); $this->updateBookSize($bookWidth, $bookHeight); $bookSizeFound = true; } // Convert to png as needed if (MediaManager::isConvertableImage($source)) { CakeLog::debug('[ImageProcessor::processBook] Converting ' . $source . ' to png'); $mediaManager->imageConvertToPng($source, $source); } // Resize image to max dimension. $image = new Imagick($source); $width = $image->getimagewidth(); $height = $image->getimageheight(); // Get new width and height list($newWidth, $newHeight) = $this->getResizedDimensionsForMaxPixels($width, $height); if ($newHeight != $height || $newWidth != $width) { CakeLog::debug('[ImageProcessor::processBook] ' . $source . ' resized for max pixel limits to ' . $newWidth . 'x' . $newHeight); // Resize the original image $img = new Imagick($source); $img->resizeimage($newWidth, $newHeight, Imagick::FILTER_LANCZOS, 1, false); $img->writeimage(); } $this->addImageAssetToBook($source, 'images/backgrounds/'); $this->savePageHTML('', $pageNumber, null, '../images/backgrounds/' . basename($source)); @unlink($source); $this->savePageCSS('', $pageNumber); // Count page $pageNumber++; // Update the progress in database every 10th page. $this->progress->incrementStep(); } //handle any non-source assets included with the book source files $this->importSourceAssets(); $this->setCoverImage(); // Save default book CSS $this->saveBookCSS(''); // Generate thumbnails $this->generateThumbnails(1, $pageCount); $this->updatePageCount($pageCount); CakeLog::debug('[ImageProcessor::processBook] Book Processing Complete'); }