/** * @param int $intX * @param int $intY * @param int $intWidth * @param int $intHeight * @param string $strColor */ public function __construct($intX, $intY, $intWidth, $intHeight, $strColor = "#FFFFFF") { $this->intX = $intX; $this->intY = $intY; $this->arrColor = class_image2::parseColorRgb($strColor); $this->intWidth = $intWidth; $this->intHeight = $intHeight; }
/** * @param int $intStartX * @param int $intStartY * @param int $intEndX * @param int $intEndY * @param string $strColor */ public function __construct($intStartX, $intStartY, $intEndX, $intEndY, $strColor = "#FFFFFF") { $this->intStartX = $intStartX; $this->intStartY = $intStartY; $this->arrColor = class_image2::parseColorRgb($strColor); $this->intEndX = $intEndX; $this->intEndY = $intEndY; }
/** * @param string $strText * @param int $intX * @param int $intY * @param double $floatSize * @param string $strColor * @param string $strFont * @param float $floatAngle */ public function __construct($strText, $intX, $intY, $floatSize, $strColor = "#000000", $strFont = "dejavusans.ttf", $floatAngle = 0.0) { $this->strText = $strText; $this->intX = $intX; $this->intY = $intY; $this->floatSize = $floatSize; $this->arrColor = class_image2::parseColorRgb($strColor); $this->strFont = $strFont; $this->floatAngle = $floatAngle; }
public function testParseColorRgbaDecimal() { list($red, $green, $blue, $alpha) = class_image2::parseColorRgb("rgba(255,0,16,1.0)"); $this->assertEquals($red, 255); $this->assertEquals($green, 0); $this->assertEquals($blue, 16); $this->assertEquals($alpha, 127); list($red, $green, $blue, $alpha) = class_image2::parseColorRgb("rgba(255,0,16,1.5)"); $this->assertEquals($red, 255); $this->assertEquals($green, 0); $this->assertEquals($blue, 16); $this->assertEquals($alpha, 127); list($red, $green, $blue, $alpha) = class_image2::parseColorRgb("rgba(255,0,16,00.83)"); $this->assertEquals($red, 255); $this->assertEquals($green, 0); $this->assertEquals($blue, 16); $this->assertEquals($alpha, 105); }
/** * 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; }
<?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"; }
/** * Generates a captcha image to defend bots. * To generate a captcha image, use "kajonaCaptcha" as image-param * when calling image.php * Up to now, the size-params are ignored during the creation of a * captcha image * * @return void */ public function generateCaptchaImage() { if ($this->intMaxWidth == 0 || $this->intMaxWidth > 500) { $intWidth = 200; } else { $intWidth = $this->intMaxWidth; } if ($this->intMaxHeight == 0 || $this->intMaxHeight > 500) { $intHeight = 50; } else { $intHeight = $this->intMaxHeight; } $intMinfontSize = 15; $intMaxFontSize = 22; $intWidthPerChar = 30; $strCharsPossible = "abcdefghijklmnpqrstuvwxyz123456789"; $intHorizontalOffset = 10; $intVerticalOffset = 10; $intForegroundOffset = 2; $strCharactersPlaced = ""; //init the random-function srand((double) microtime() * 1000000); //v2 version $objImage2 = new class_image2(); $objImage2->create($intWidth, $intHeight); $objImage2->addOperation(new class_image_rectangle(0, 0, $intWidth, $intHeight, "#FFFFFF")); //draw vertical lines $intStart = 5; while ($intStart < $intWidth - 5) { $objImage2->addOperation(new class_image_line($intStart, 0, $intStart, $intWidth, $this->generateGreyLikeColor())); $intStart += rand(10, 17); } //draw horizontal lines $intStart = 5; while ($intStart < $intHeight - 5) { $objImage2->addOperation(new class_image_line(0, $intStart, $intWidth, $intStart, $this->generateGreyLikeColor())); $intStart += rand(10, 17); } //draw floating horizontal lines for ($intI = 0; $intI <= 3; $intI++) { $intXPrev = 0; $intYPrev = rand(0, $intHeight); while ($intXPrev <= $intWidth) { $intNewX = rand($intXPrev, $intXPrev + 50); $intNewY = rand(0, $intHeight); $objImage2->addOperation(new class_image_line($intXPrev, $intYPrev, $intNewX, $intNewY, $this->generateGreyLikeColor())); $intXPrev = $intNewX; $intYPrev = $intNewY; } } //calculate number of characters on the image $intNumberOfChars = floor($intWidth / $intWidthPerChar); //place characters in the image for ($intI = 0; $intI < $intNumberOfChars; $intI++) { //character to place $strCurrentChar = $strCharsPossible[rand(0, uniStrlen($strCharsPossible) - 1)]; $strCharactersPlaced .= $strCurrentChar; //color to use $intCol1 = rand(0, 200); $intCol2 = rand(0, 200); $intCol3 = rand(0, 200); //fontsize $intSize = rand($intMinfontSize, $intMaxFontSize); //calculate x and y pos $intX = $intHorizontalOffset + $intI * $intWidthPerChar; $intY = $intHeight - rand($intVerticalOffset, $intHeight - $intMaxFontSize); //the angle $intAngle = rand(-30, 30); //place the background character $objImage2->addOperation(new class_image_text($strCurrentChar, $intX, $intY, $intSize, "rgb(" . $intCol1 . "," . $intCol2 . "," . $intCol3 . ")", "dejavusans.ttf", $intAngle)); //place the foreground charater $objImage2->addOperation(new class_image_text($strCurrentChar, $intX + $intForegroundOffset, $intY + $intForegroundOffset, $intSize, "rgb(" . ($intCol1 + 50) . "," . ($intCol2 + 50) . "," . ($intCol3 + 50) . ")", "dejavusans.ttf", $intAngle)); } //register placed string to session class_carrier::getInstance()->getObjSession()->setCaptchaCode($strCharactersPlaced); //and send it to the browser //force no-cache headers class_response_object::getInstance()->addHeader("Expires: Thu, 19 Nov 1981 08:52:00 GMT", true); class_response_object::getInstance()->addHeader("Cache-Control: no-store, no-cache, must-revalidate, private", true); class_response_object::getInstance()->addHeader("Pragma: no-cache", true); $objImage2->setUseCache(false); $objImage2->sendToBrowser(class_image2::FORMAT_JPG); }
/** * @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++; } } }
/** * @param double $floatAngle * @param string $strColor */ public function __construct($floatAngle, $strColor = "#000000") { $this->floatAngle = $floatAngle; $this->arrColor = class_image2::parseColorRgb($strColor); }