/** * Print screenshot * * @param Menta_Util_Screenshot $screenshot * @return string */ protected function printScreenshot(Menta_Util_Screenshot $screenshot) { $result = ''; $directory = $this->get('basedir'); try { $fileName = 'screenshot_' . $screenshot->getId() . '.png'; $thumbnailName = 'screenshot_' . $screenshot->getId() . '_thumb.png'; if (is_file($directory . DIRECTORY_SEPARATOR . $fileName)) { $result .= 'Screenshot already exists. Skipping.'; return $result; } $screenshot->writeToDisk($directory . DIRECTORY_SEPARATOR . $fileName); // create thumbnail $simpleImage = new Menta_Util_SimpleImage($directory . DIRECTORY_SEPARATOR . $fileName); $simpleImage->resizeToWidth(self::THUMBNAIL_WIDTH)->save($directory . DIRECTORY_SEPARATOR . $thumbnailName, IMAGETYPE_PNG); $printSingleFile = true; if ($this->pdiffEnabled()) { $printSingleFile = false; // instead of before/after widget $previousPath = $this->getPreviousPath(); $previousScreenshot = $previousPath . DIRECTORY_SEPARATOR . $fileName; if ($previousPath && is_file($previousScreenshot)) { if (md5_file($directory . DIRECTORY_SEPARATOR . $fileName) != md5_file($previousScreenshot)) { $fileNamePrev = 'screenshot_' . $screenshot->getId() . '.prev.png'; $thumbnailNamePrev = 'screenshot_' . $screenshot->getId() . '_thumb.prev.png'; // actual image if (file_exists($directory . DIRECTORY_SEPARATOR . $fileNamePrev)) { unlink($directory . DIRECTORY_SEPARATOR . $fileNamePrev); } link($previousScreenshot, $directory . DIRECTORY_SEPARATOR . $fileNamePrev); // thumbnail if (file_exists($directory . DIRECTORY_SEPARATOR . $thumbnailNamePrev)) { unlink($directory . DIRECTORY_SEPARATOR . $thumbnailNamePrev); } link($previousPath . DIRECTORY_SEPARATOR . $thumbnailName, $directory . DIRECTORY_SEPARATOR . $thumbnailNamePrev); // $result .= '<a class="previous" title="'.$screenshot->getTitle().'" href="'.$fileNamePrev.'">'; // $result .= '<img src="'.$thumbnailNamePrev.'" width="'.self::THUMBNAIL_WIDTH.'" />'; // $result .= '</a>'; // before after viewer $size = getimagesize($directory . DIRECTORY_SEPARATOR . $thumbnailName); $id = uniqid('beforeafter_'); $result .= '<div class="beforeafter">'; $result .= '<div id="' . $id . '">'; $result .= '<div><img alt="after" src="' . $fileName . '" ' . $size[3] . ' /></div>'; $result .= '<div><img alt="before" src="' . $fileNamePrev . '" ' . $size[3] . ' /></div>'; $result .= '</div>'; $result .= '<script type="text/javascript">$(function(){ $("#' . $id . '").beforeAfter(); }); </script>'; $result .= '</div>'; $fileNameDiff = 'screenshot_' . $screenshot->getId() . '.diff.png'; $thumbnailNameDiff = 'screenshot_' . $screenshot->getId() . '_thumb.diff.png'; $this->createPdiff($directory . DIRECTORY_SEPARATOR . $fileNamePrev, $directory . DIRECTORY_SEPARATOR . $fileName, $directory . DIRECTORY_SEPARATOR . $fileNameDiff); // create thumbnail $simpleImage = new Menta_Util_SimpleImage($directory . DIRECTORY_SEPARATOR . $fileNameDiff); $simpleImage->resizeToWidth(self::THUMBNAIL_WIDTH)->save($directory . DIRECTORY_SEPARATOR . $thumbnailNameDiff, IMAGETYPE_PNG); $size = getimagesize($directory . DIRECTORY_SEPARATOR . $thumbnailNameDiff); $result .= '<a class="current" title="' . $screenshot->getTitle() . '" href="' . $fileNameDiff . '">'; $result .= '<img src="' . $thumbnailNameDiff . '" ' . $size[3] . ' />'; $result .= '</a>'; } else { $printSingleFile = true; $result .= '<div class="info">PDIFF: Exact match.</div>'; } } elseif ($previousPath && !is_file($previousScreenshot)) { $printSingleFile = true; $result .= '<div class="info">PDIFF: Couldn\'t find previous file</div>'; } else { $printSingleFile = true; $result .= '<div class="info">PDIFF: Couldn\'t find previous path</div>'; } } if ($printSingleFile) { $size = getimagesize($directory . DIRECTORY_SEPARATOR . $thumbnailName); $result .= '<a class="current" title="' . $screenshot->getTitle() . '" href="' . $fileName . '">'; $result .= '<img src="' . $thumbnailName . '" ' . $size[3] . ' />'; $result .= '</a>'; } } catch (Exception $e) { $result .= 'EXCEPTION: ' . $e->getMessage(); } return $result; }
/** * @param string $title * * @return Menta_Util_Screenshot */ public function getScreenShot($title = '') { // don't init a new session if there is none if (!Menta_SessionManager::activeSessionExists()) { return false; } $screenshotHelper = Menta_ComponentManager::get('Menta_Component_Helper_Screenshot'); /* @var $screenshotHelper Menta_Component_Helper_Screenshot */ $base64Image = $screenshotHelper->takeScreenshotToString(); $time = time(); // put data into the screenshot object $screenshot = new Menta_Util_Screenshot(); $screenshot->setBase64Image($base64Image); $screenshot->setTime($time); if (!is_null($title)) { $screenshot->setTitle($title); } $screenshot->setLocation($this->getSession()->url()); return $screenshot; }
/** * @param Menta_Util_Screenshot $screenshot * * @return string */ protected function renderScreenShot(Menta_Util_Screenshot $screenshot) { $result = ''; $directory = $this->get('basedir'); try { $fileName = 'screenshot_' . $screenshot->getId() . '.png'; $thumbnailName = 'screenshot_' . $screenshot->getId() . '_thumb.png'; if (is_file($directory . DIRECTORY_SEPARATOR . $fileName)) { return 'Screenshot already exists. Skipping.'; } $screenshot->writeToDisk($directory . DIRECTORY_SEPARATOR . $fileName); // create thumbnail $simpleImage = new Menta_Util_SimpleImage($directory . DIRECTORY_SEPARATOR . $fileName); $simpleImage->resizeToWidth(100)->save($directory . DIRECTORY_SEPARATOR . $thumbnailName, IMAGETYPE_PNG); $result .= '<a class="current" title="' . $screenshot->getTitle() . '" href="' . $fileName . '">'; $result .= '<img src="' . $thumbnailName . '" width="100" />'; $result .= '</a>'; $previousPath = $this->getPreviousPath(); $previousScreenshot = $previousPath . DIRECTORY_SEPARATOR . $fileName; if ($previousPath && is_file($previousScreenshot)) { if (md5_file($directory . DIRECTORY_SEPARATOR . $fileName) != md5_file($previousScreenshot)) { $fileNamePrev = 'screenshot_' . $screenshot->getId() . '.prev.png'; $thumbnailNamePrev = 'screenshot_' . $screenshot->getId() . '_thumb.prev.png'; // actual image if (file_exists($directory . DIRECTORY_SEPARATOR . $fileNamePrev)) { unlink($directory . DIRECTORY_SEPARATOR . $fileNamePrev); } link($previousScreenshot, $directory . DIRECTORY_SEPARATOR . $fileNamePrev); // thumbnail if (file_exists($directory . DIRECTORY_SEPARATOR . $thumbnailNamePrev)) { unlink($directory . DIRECTORY_SEPARATOR . $thumbnailNamePrev); } link($previousPath . DIRECTORY_SEPARATOR . $thumbnailName, $directory . DIRECTORY_SEPARATOR . $thumbnailNamePrev); $result .= '<a class="previous" title="' . $screenshot->getTitle() . '" href="' . $fileNamePrev . '">'; $result .= '<img src="' . $thumbnailNamePrev . '" width="100" />'; $result .= '</a>'; $fileNameDiff = 'screenshot_' . $screenshot->getId() . '.diff.png'; $thumbnailNameDiff = 'screenshot_' . $screenshot->getId() . '_thumb.diff.png'; $this->createPdiff($directory . DIRECTORY_SEPARATOR . $fileNamePrev, $directory . DIRECTORY_SEPARATOR . $fileName, $directory . DIRECTORY_SEPARATOR . $fileNameDiff); // create thumbnail $simpleImage = new Menta_Util_SimpleImage($directory . DIRECTORY_SEPARATOR . $fileNameDiff); $simpleImage->resizeToWidth(100)->save($directory . DIRECTORY_SEPARATOR . $thumbnailNameDiff, IMAGETYPE_PNG); $result .= '<a class="current" title="' . $screenshot->getTitle() . '" href="' . $fileNameDiff . '">'; $result .= '<img src="' . $thumbnailNameDiff . '" width="100" />'; $result .= '</a>'; return $result; } else { $result .= 'PDIFF: Exact match.'; } } elseif ($previousPath && !is_file($previousScreenshot)) { $result .= 'PDIFF: Couldn\'t find previous file ' . getcwd() . ' ' . $previousScreenshot; } } catch (Exception $e) { $result .= 'EXCEPTION: ' . $e->getMessage(); } return $result; }