/** * Constructor */ public function __construct($bookId) { parent::__construct($bookId); $this->epub = new EpubManager($bookId); $this->workingDir = $this->initWorkingDir(); $this->startPage = $this->getPageCount(); }
protected function cropImage($idmlImage, $idmlRectangle, $s3File) { $ffi = $idmlRectangle->frameFittingOption; if ($ffi->hasCroppingInstructions()) { if (!$this->FileManager->exists($s3File)) { CakeLog::warning('[IdmlResourceManager::cropImage] Source file ' . $s3File . ' does not exist.'); return false; } // InDesign uses 72ppi as its base units for IDML // convert the cropping instruction units to image pixel units $leftCrop = $ffi->leftCrop * ($idmlImage->ppiX / 72); $rightCrop = $ffi->rightCrop * ($idmlImage->ppiX / 72); $topCrop = $ffi->topCrop * ($idmlImage->ppiY / 72); $bottomCrop = $ffi->bottomCrop * ($idmlImage->ppiY / 72); // convert the image dimensions from InDesign units to real pixels $originalImageWidth = $idmlImage->width * ($idmlImage->ppiX / 72); $originalImageHeight = $idmlImage->height * ($idmlImage->ppiY / 72); $widthOfCrop = $originalImageWidth - ($rightCrop + $leftCrop); $heightOfCrop = $originalImageHeight - ($topCrop + $bottomCrop); // download from S3 to local computer $tmp = $this->FileManager->getTmpPath(); $basename = pathinfo($s3File, PATHINFO_BASENAME); $localFile = $tmp . DS . $basename; $this->FileManager->copy($s3File, $localFile); $result = true; // Crop $imagick = new Imagick($localFile); if ($imagick) { try { $imagick->cropImage($widthOfCrop, $heightOfCrop, $leftCrop, $topCrop); $imagick->writeImage(); } catch (Exception $e) { CakeLog::warning('[IdmlResourceManager::cropImage] Failed to crop ' . $localFile); $result = false; } $imagick->clear(); $imagick->destroy(); } // upload from local computer to S3 $this->FileManager->copy($localFile, $s3File); $this->processor->patchSourceAssetList($localFile, $localFile); return $result; } }