/**
  * Tries to save the passed cropping.
  * The following params are needed:
  * action = saveCropping
  * folder = the files' location
  * file = the file to crop
  * systemid = the repo-id
  * intX
  * intY
  * intWidth
  * intHeight
  * @return string
  * @permissions edit
  */
 protected function actionSaveCropping()
 {
     $strReturn = "";
     $strFile = $this->getParam("file");
     $objImage = new class_image2();
     $objImage->setUseCache(false);
     $objImage->load($strFile);
     $objImage->addOperation(new class_image_crop($this->getParam("intX"), $this->getParam("intY"), $this->getParam("intWidth"), $this->getParam("intHeight")));
     if ($objImage->save($strFile)) {
         class_logger::getInstance()->addLogRow("cropped file " . $strFile, class_logger::$levelInfo);
         $strReturn .= "<message>" . xmlSafeString($this->getLang("xml_cropping_success")) . "</message>";
     } else {
         class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_UNAUTHORIZED);
         $strReturn .= "<message><error>" . xmlSafeString($this->getLang("commons_error_permissions")) . "</error></message>";
     }
     return $strReturn;
 }
Пример #2
0
 /**
  * Wrapper to the real, fast resizing
  * @return void
  */
 private function resizeImage()
 {
     //Load the image-dimensions
     if (is_file(_realpath_ . $this->strFilename) && (uniStrpos($this->strFilename, "/files") !== false || uniStrpos($this->strFilename, "/templates") !== false)) {
         //check headers, maybe execution could be terminated right here
         if (checkConditionalGetHeaders(md5(md5_file(_realpath_ . $this->strFilename) . $this->intMaxWidth . $this->intMaxHeight . $this->intFixedWidth . $this->intFixedHeight))) {
             class_response_object::getInstance()->sendHeaders();
             return;
         }
         $objImage = new class_image2();
         $objImage->load($this->strFilename);
         $objImage->addOperation(new class_image_scale_and_crop($this->intFixedWidth, $this->intFixedHeight));
         $objImage->addOperation(new class_image_scale($this->intMaxWidth, $this->intMaxHeight));
         //send the headers for conditional gets
         setConditionalGetHeaders(md5(md5_file(_realpath_ . $this->strFilename) . $this->intMaxWidth . $this->intMaxHeight . $this->intFixedWidth . $this->intFixedHeight));
         //TODO: add expires header for browser caching (optional)
         /*
         $intCacheSeconds = 604800; //default: 1 week (60*60*24*7)
         header("Expires: ".gmdate("D, d M Y H:i:s", time() + $intCacheSeconds)." GMT", true);
         header("Cache-Control: public, max-age=".$intCacheSeconds, true);
         header("Pragma: ", true);
         */
         //and send it to the browser
         $objImage->setJpegQuality((int) $this->intQuality);
         $objImage->sendToBrowser();
         return;
     }
     class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_NOT_FOUND);
     class_response_object::getInstance()->sendHeaders();
 }
Пример #3
0
<?php

$floatAngle = 90.0;
$objImage = new class_image2();
$objImage->setUseCache(false);
if (!$objImage->load("/files/images/samples/P9066809.JPG")) {
    echo "Could not load file.\n";
}
$objImage->addOperation(new class_image_rotate($floatAngle, "#ffffffff"));
$objImage->addOperation(new class_image_scale_and_crop(800, 1350));
if (!$objImage->save("/files/cache/P9066809_transformed.PNG", class_image2::FORMAT_PNG)) {
    echo "File not saved.\n";
}
 /**
  * @param $strPath
  * @return void
  */
 private function recursiveImageProcessing($strPath)
 {
     $objFilesystem = new class_filesystem();
     $arrFilesFolders = $objFilesystem->getCompleteList($strPath, array(".jpg", ".jpeg", ".png", ".gif"), array(), array(".", "..", ".svn"));
     $this->intFilesTotal += $arrFilesFolders["nrFiles"];
     foreach ($arrFilesFolders["folders"] as $strOneFolder) {
         $this->recursiveImageProcessing($strPath . "/" . $strOneFolder);
     }
     foreach ($arrFilesFolders["files"] as $arrOneFile) {
         $strImagePath = $strPath . "/" . $arrOneFile["filename"];
         $objImage = new class_image2();
         $objImage->setUseCache(false);
         $objImage->load($strImagePath);
         $objImage->addOperation(new class_image_scale($this->intMaxWidth, $this->intMaxHeight));
         if ($objImage->save($strImagePath)) {
             $this->intFilesProcessed++;
         }
     }
 }