/** * Saves the new image wherever you want * @todo In case the PHP script has no write access to the location set by $this->newImageFile, * the image shall be sent to the output buffer and then be put into the new file * location using the FileSystemFile object. * @access public * @param string $file The path for the image file to be written. * @param booelan $forceOverwrite Force overwriting existing files if true. * @return boolean True on success, false otherwise. */ public function saveNewImage($file, $forceOverwrite = false) { // TODO: Add some sort of diagnostics (Message) here and elsewhere in this class if (!$this->imageCheck) { return false; } if (empty($this->newImage)) { return false; } if (file_exists($file)) { if (!$forceOverwrite) { return false; } \Cx\Lib\FileSystem\FileSystem::makeWritable($file); } else { try { $objFile = new \Cx\Lib\FileSystem\File($file); $objFile->touch(); } catch (\Cx\Lib\FileSystem\FileSystemException $e) { \DBG::msg($e->getMessage()); } } // TODO: Unfortunately, the functions imagegif(), imagejpeg() and imagepng() can't use the Contrexx FileSystem wrapper, // therefore we need to set the global write access image files. // This issue might be solved by using the output-buffer and write the image manually afterwards. // // IMPORTANT: In case something went wrong (see bug #1441) and the path $strPathNew.$strFileNew refers to a directory // we must abort the operation here, otherwise we would remove the execution flag on a directory, which would // cause to remove any browsing access to the directory. if (is_dir($file)) { return false; } \Cx\Lib\FileSystem\FileSystem::chmod($file, 0666); //\Cx\Lib\FileSystem\FileSystem::CHMOD_FILE); $this->newImageFile = $file; if ($this->newImageType == self::IMG_TYPE_PNG) { $this->setTransparency(); } switch ($this->newImageType) { case self::IMG_TYPE_GIF: $function = 'imagegif'; if (!function_exists($function)) { $function = 'imagejpeg'; } break; case self::IMG_TYPE_JPEG: $function = 'imagejpeg'; break; case self::IMG_TYPE_PNG: // make a jpeg thumbnail, too $function = 'imagepng'; break; default: return false; } // Only adjust quality, if it is set. if ($this->newImageQuality != '') { $function($this->newImage, $this->newImageFile, $this->getQuality()); } else { $function($this->newImage, $this->newImageFile); } return true; }
/** * Get thumbnails * * Get the thumbnails from a day in the archive. * Create the thumbnails if they don't already exists. * * @access private */ function _getThumbs() { $path = ASCMS_DOCUMENT_ROOT . "/" . $this->camSettings['archivePath'] . '/' . $this->date . '/'; $objDirectory = @opendir($path); $chmoded = false; if ($objDirectory) { while ($file = readdir($objDirectory)) { if ($file != "." && $file != "..") { //check and create thumbs $thumb = ASCMS_DOCUMENT_ROOT . $this->camSettings['thumbnailPath'] . '/tn_' . $this->date . '_' . $file; if (!\Cx\Lib\FileSystem\FileSystem::exists($thumb)) { if (!$chmoded) { \Cx\Lib\FileSystem\FileSystem::chmod($this->camSettings['thumbnailPath'], '777'); $chmoded = true; } //create thumb $im1 = @imagecreatefromjpeg($path . $file); //erstellt ein Abbild im Speicher if ($im1) { /* Pr�fen, ob fehlgeschlagen */ // check_jpeg($thumb, $fix=false ); $size = getimagesize($path . $file); //ermittelt die Gr��e des Bildes $breite = $size[0]; //die Breite des Bildes $hoehe = $size[1]; //die H�he des Bildes $breite_neu = $this->camSettings['thumbMaxSize']; //die breite des Thumbnails $factor = $breite / $this->camSettings['thumbMaxSize']; //berechnungsfaktor $hoehe_neu = $size[1] / $factor; //die H�he des Thumbnails //$im2=imagecreate($breite_neu,$hoehe_neu); //Thumbnail im Speicher erstellen $im2 = @imagecreatetruecolor($breite_neu, $hoehe_neu); imagecopyresized($im2, $im1, 0, 0, 0, 0, $breite_neu, $hoehe_neu, $breite, $hoehe); imagejpeg($im2, $thumb); //Thumbnail speichern imagedestroy($im1); //Speicherabbild wieder l�schen imagedestroy($im2); //Speicherabbild wieder l�schen } } //show pictures $minHour = date('G', $this->camSettings['showFrom']); $minMinutes = date('i', $this->camSettings['showFrom']); $maxHour = date('G', $this->camSettings['showTill']); $maxMinutes = date('i', $this->camSettings['showTill']); $hour = substr($file, 4, 2); $min = substr($file, 13, 2); $min = !empty($min) ? $min : "00"; $time = $hour . ":" . $min . " Uhr"; $minTime = mktime($minHour, $minMinutes); $maxTime = mktime($maxHour, $maxMinutes); $nowTime = mktime($hour, $min); /* * only show archive images if they are in range */ if ($nowTime <= $maxTime && $nowTime >= $minTime) { if ($this->camSettings['shadowboxActivate'] == 1) { $linkUrl = ASCMS_PATH_OFFSET . $this->camSettings['archivePath'] . '/' . $this->date . '/' . $file; } else { $linkUrl = '?section=Livecam&file=' . $this->date . '/' . $file; } $arrThumbnail = array('link_url' => $linkUrl, 'image_url' => $this->camSettings['thumbnailPath'] . "/tn_" . $this->date . "_" . $file, 'time' => $time); array_push($this->_arrArchiveThumbs, $arrThumbnail); } } } closedir($objDirectory); } }
/** * Create an Image * @param string $strPathOld: The old path of the image * @param string $strPathNew: The new path for the created image * @param string $strFileOld: The name of the old file * @param string $strFileNew: The name of the new file * @param integer $intNewWidth: Width of the new image * @param integer $intNewHeight: Height of the new image * @param integer $intQuality: Quality of the new image */ function createImages_JPG_GIF_PNG($strPathOld, $strPathNew, $strFileOld, $strFileNew, $intNewWidth, $intNewHeight, $intQuality) { global $_ARRAYLANG; //TODO: sometimes, strings are passed... this is a workaround $intNewWidth = intval($intNewWidth); $intNewHeight = intval($intNewHeight); //copy image $intSize = getimagesize($strPathOld . $strFileOld); //ermittelt die Gr��e des Bildes $intWidth = $intSize[0]; //die Breite des Bildes $intHeight = $intSize[1]; //die H�he des Bildes $strType = $intSize[2]; //type des Bildes if (file_exists($strPathNew . $strFileNew)) { \Cx\Lib\FileSystem\FileSystem::makeWritable($strPathNew . $strFileNew); } else { try { $objFile = new \Cx\Lib\FileSystem\File($strPathNew . $strFileNew); $objFile->touch(); $objFile->makeWritable(); } catch (\Cx\Lib\FileSystem\FileSystemException $e) { \DBG::msg($e->getMessage()); } } // TODO: Unfortunately, the functions imagegif(), imagejpeg() and imagepng() can't use the Cloudrexx FileSystem wrapper, // therefore we need to set the global write access image files. // This issue might be solved by using the output-buffer and write the image manually afterwards. // // IMPORTANT: In case something went wrong (see bug #1441) and the path $strPathNew.$strFileNew refers to a directory // we must abort the operation here, otherwise we would remove the execution flag on a directory, which would // cause to remove any browsing access to the directory. if (is_dir($strPathNew . $strFileNew)) { return false; } \Cx\Lib\FileSystem\FileSystem::chmod($strPathNew . $strFileNew, 0666); //\Cx\Lib\FileSystem\FileSystem::CHMOD_FILE); //fix cases of zeroes if ($intNewWidth == 0) { if ($intNewHeight == 0) { $intNewHeight = $this->arrSettings['standard_height_abs']; } if ($intNewHeight == 0) { //set a standard value if the settings default to 0 $intNewHeight = 100; } $intNewWidth = round($intWidth * $intNewHeight / $intHeight, 0); } else { if ($intNewHeight == 0) { $intNewHeight = round($intHeight * $intNewWidth / $intWidth, 0); } } $objSystem = new \FWSystem(); if ($objSystem === false) { return false; } if (is_array($intSize)) { $memoryLimit = $objSystem->getBytesOfLiteralSizeFormat(@ini_get('memory_limit')); // a $memoryLimit of zero means that there is no limit. so let's try it and hope that the host system has enough memory if (!empty($memoryLimit)) { $potentialRequiredMemory = $intSize[0] * $intSize[1] * ($intSize['bits'] / 8) * $intSize['channels'] * 1.8 * 2; if (function_exists('memory_get_usage')) { $potentialRequiredMemory += memory_get_usage(); } else { // add a default of 10 MBytes $potentialRequiredMemory += 10 * pow(1024, 2); } if ($potentialRequiredMemory > $memoryLimit) { // try to set a higher memory_limit @ini_set('memory_limit', $potentialRequiredMemory); $curr_limit = $objSystem->getBytesOfLiteralSizeFormat(@ini_get('memory_limit')); if ($curr_limit < $potentialRequiredMemory) { return false; } } } } else { return false; } switch ($strType) { case 1: //GIF if ($this->boolGifEnabled) { $handleImage1 = ImageCreateFromGif($strPathOld . $strFileOld); $handleImage2 = @ImageCreateTrueColor($intNewWidth, $intNewHeight); ImageCopyResampled($handleImage2, $handleImage1, 0, 0, 0, 0, $intNewWidth, $intNewHeight, $intWidth, $intHeight); ImageGif($handleImage2, $strPathNew . $strFileNew); ImageDestroy($handleImage1); ImageDestroy($handleImage2); } else { $this->strErrMessage = $_ARRAYLANG['TXT_GALLERY_NO_GIF_SUPPORT']; } break; case 2: //JPG if ($this->boolJpgEnabled) { $handleImage1 = ImageCreateFromJpeg($strPathOld . $strFileOld); $handleImage2 = ImageCreateTrueColor($intNewWidth, $intNewHeight); ImageCopyResampled($handleImage2, $handleImage1, 0, 0, 0, 0, $intNewWidth, $intNewHeight, $intWidth, $intHeight); ImageJpeg($handleImage2, $strPathNew . $strFileNew, $intQuality); ImageDestroy($handleImage1); ImageDestroy($handleImage2); } else { $this->strErrMessage = $_ARRAYLANG['TXT_GALLERY_NO_JPG_SUPPORT']; } break; case 3: //PNG if ($this->boolPngEnabled) { $handleImage1 = ImageCreateFromPNG($strPathOld . $strFileOld); $handleImage2 = @ImageCreateTrueColor($intNewWidth, $intNewHeight); ImageAlphaBlending($handleImage2, false); ImageSaveAlpha($handleImage2, true); ImageCopyResampled($handleImage2, $handleImage1, 0, 0, 0, 0, $intNewWidth, $intNewHeight, $intWidth, $intHeight); ImagePNG($handleImage2, $strPathNew . $strFileNew); ImageDestroy($handleImage1); ImageDestroy($handleImage2); } else { $this->strErrMessage = $_ARRAYLANG['TXT_GALLERY_NO_PNG_SUPPORT']; } break; } return true; }