コード例 #1
0
ファイル: phpthumb.filters.php プロジェクト: exside/phpThumb
 public static function ImprovedImageRotate(&$gdimg_source, $rotate_angle = 0, $config_background_hexcolor = 'FFFFFF', $bg = null, &$phpThumbObject)
 {
     while ($rotate_angle < 0) {
         $rotate_angle += 360;
     }
     $rotate_angle = $rotate_angle % 360;
     if ($rotate_angle != 0) {
         $background_color = phpthumb_functions::ImageHexColorAllocate($gdimg_source, $config_background_hexcolor);
         if (phpthumb_functions::gd_version() >= 2 && !$bg && $rotate_angle % 90) {
             //$this->DebugMessage('Using alpha rotate', __FILE__, __LINE__);
             if ($gdimg_rotate_mask = phpthumb_functions::ImageCreateFunction(ImageSX($gdimg_source), ImageSY($gdimg_source))) {
                 for ($i = 0; $i <= 255; $i++) {
                     $color_mask[$i] = ImageColorAllocate($gdimg_rotate_mask, $i, $i, $i);
                 }
                 ImageFilledRectangle($gdimg_rotate_mask, 0, 0, ImageSX($gdimg_rotate_mask), ImageSY($gdimg_rotate_mask), $color_mask[255]);
                 $imageX = ImageSX($gdimg_source);
                 $imageY = ImageSY($gdimg_source);
                 for ($x = 0; $x < $imageX; $x++) {
                     for ($y = 0; $y < $imageY; $y++) {
                         $pixelcolor = phpthumb_functions::GetPixelColor($gdimg_source, $x, $y);
                         ImageSetPixel($gdimg_rotate_mask, $x, $y, $color_mask[255 - round($pixelcolor['alpha'] * 255 / 127)]);
                     }
                 }
                 $gdimg_rotate_mask = ImageRotate($gdimg_rotate_mask, $rotate_angle, $color_mask[0]);
                 $gdimg_source = ImageRotate($gdimg_source, $rotate_angle, $background_color);
                 ImageAlphaBlending($gdimg_source, false);
                 ImageSaveAlpha($gdimg_source, true);
                 //$this->is_alpha = true;
                 $phpThumbFilters = new phpthumb_filters();
                 //$phpThumbFilters->phpThumbObject = $this;
                 $phpThumbFilters->phpThumbObject = $phpThumbObject;
                 $phpThumbFilters->ApplyMask($gdimg_rotate_mask, $gdimg_source);
                 ImageDestroy($gdimg_rotate_mask);
             } else {
                 //$this->DebugMessage('ImageCreateFunction() failed', __FILE__, __LINE__);
             }
         } else {
             if (phpthumb_functions::gd_version() < 2) {
                 //$this->DebugMessage('Using non-alpha rotate because gd_version is "'.phpthumb_functions::gd_version().'"', __FILE__, __LINE__);
             } elseif ($bg) {
                 //$this->DebugMessage('Using non-alpha rotate because $this->bg is "'.$bg.'"', __FILE__, __LINE__);
             } elseif ($rotate_angle % 90) {
                 //$this->DebugMessage('Using non-alpha rotate because ($rotate_angle % 90) = "'.($rotate_angle % 90).'"', __FILE__, __LINE__);
             } else {
                 //$this->DebugMessage('Using non-alpha rotate because $this->thumbnailFormat is "'.$this->thumbnailFormat.'"', __FILE__, __LINE__);
             }
             if (ImageColorTransparent($gdimg_source) >= 0) {
                 // ImageRotate() forgets all about an image's transparency and sets the transparent color to black
                 // To compensate, flood-fill the transparent color of the source image with the specified background color first
                 // then rotate and the colors should match
                 if (!function_exists('ImageIsTrueColor') || !ImageIsTrueColor($gdimg_source)) {
                     // convert paletted image to true-color before rotating to prevent nasty aliasing artifacts
                     //$this->source_width  = ImageSX($gdimg_source);
                     //$this->source_height = ImageSY($gdimg_source);
                     $gdimg_newsrc = phpthumb_functions::ImageCreateFunction(ImageSX($gdimg_source), ImageSY($gdimg_source));
                     $background_color = phpthumb_functions::ImageHexColorAllocate($gdimg_newsrc, $config_background_hexcolor);
                     ImageFilledRectangle($gdimg_newsrc, 0, 0, ImageSX($gdimg_source), ImageSY($gdimg_source), phpthumb_functions::ImageHexColorAllocate($gdimg_newsrc, $config_background_hexcolor));
                     ImageCopy($gdimg_newsrc, $gdimg_source, 0, 0, 0, 0, ImageSX($gdimg_source), ImageSY($gdimg_source));
                     ImageDestroy($gdimg_source);
                     unset($gdimg_source);
                     $gdimg_source = $gdimg_newsrc;
                     unset($gdimg_newsrc);
                 } else {
                     ImageColorSet($gdimg_source, ImageColorTransparent($gdimg_source), hexdec(substr($config_background_hexcolor, 0, 2)), hexdec(substr($config_background_hexcolor, 2, 2)), hexdec(substr($config_background_hexcolor, 4, 2)));
                     ImageColorTransparent($gdimg_source, -1);
                 }
             }
             $gdimg_source = ImageRotate($gdimg_source, $rotate_angle, $background_color);
         }
     }
     return true;
 }
コード例 #2
0
 /**
  * Apply input levels to input image pointer (increasing contrast)
  *
  * @param resource $im GDlib Image Pointer
  * @param int $low The "low" value (close to 0)
  * @param int $high The "high" value (close to 255)
  * @return void
  */
 public function inputLevels(&$im, $low, $high)
 {
     if ($low < $high) {
         $low = MathUtility::forceIntegerInRange($low, 0, 255);
         $high = MathUtility::forceIntegerInRange($high, 0, 255);
         $delta = $high - $low;
         $totalCols = ImageColorsTotal($im);
         for ($c = 0; $c < $totalCols; $c++) {
             $cols = ImageColorsForIndex($im, $c);
             $cols['red'] = MathUtility::forceIntegerInRange(($cols['red'] - $low) / $delta * 255, 0, 255);
             $cols['green'] = MathUtility::forceIntegerInRange(($cols['green'] - $low) / $delta * 255, 0, 255);
             $cols['blue'] = MathUtility::forceIntegerInRange(($cols['blue'] - $low) / $delta * 255, 0, 255);
             ImageColorSet($im, $c, $cols['red'], $cols['green'], $cols['blue']);
         }
     }
 }
コード例 #3
0
ファイル: IconUtility.php プロジェクト: khanhdeux/typo3test
 /**
  * Creates the icon file for the function getIcon()
  *
  * @param string $iconfile Original unprocessed Icon file, relative path to PATH_typo3
  * @param string $mode Mode string, eg. "deleted" or "futuretiming" determining how the icon will look
  * @param integer $user The number of the fe_group record uid if applicable
  * @param boolean $protectSection Flag determines if the protected-section icon should be applied.
  * @param string $absFile Absolute path to file from which to create the icon.
  * @param string $iconFileName_stateTagged The filename that this icon should have had, basically [icon base name]_[flags].[extension] - used for part of temporary filename
  * @return string Filename relative to PATH_typo3
  * @access private
  */
 public static function makeIcon($iconfile, $mode, $user, $protectSection, $absFile, $iconFileName_stateTagged)
 {
     $iconFileName = 'icon_' . GeneralUtility::shortMD5($iconfile . '|' . $mode . '|-' . $user . '|' . $protectSection) . '_' . $iconFileName_stateTagged . '.' . ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png'] ? 'png' : 'gif');
     $mainpath = '../typo3temp/' . $iconFileName;
     $path = PATH_site . 'typo3temp/' . $iconFileName;
     if (file_exists(PATH_typo3 . 'icons/' . $iconFileName)) {
         // Returns if found in typo3/icons/
         return 'icons/' . $iconFileName;
     } elseif (file_exists($path)) {
         // Returns if found in ../typo3temp/icons/
         return $mainpath;
     } else {
         // Makes icon:
         if (file_exists($absFile)) {
             if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib']) {
                 // Create image pointer, if possible
                 $im = self::imagecreatefrom($absFile);
                 if ($im < 0) {
                     return $iconfile;
                 }
                 // Converting to gray scale, dimming the icon:
                 if ($mode == 'disabled' or $mode != 'futuretiming' && $mode != 'no_icon_found' && !(!$mode && $user)) {
                     $totalImageColors = ImageColorsTotal($im);
                     for ($c = 0; $c < $totalImageColors; $c++) {
                         $cols = ImageColorsForIndex($im, $c);
                         $newcol = round(($cols['red'] + $cols['green'] + $cols['blue']) / 3);
                         $lighten = $mode == 'disabled' ? 2.5 : 2;
                         $newcol = round(255 - (255 - $newcol) / $lighten);
                         ImageColorSet($im, $c, $newcol, $newcol, $newcol);
                     }
                 }
                 // Applying user icon, if there are access control on the item:
                 if ($user) {
                     if ($user < 100) {
                         // Apply user number only if lower than 100
                         $black = ImageColorAllocate($im, 0, 0, 0);
                         imagefilledrectangle($im, 0, 0, $user > 10 ? 9 : 5, 8, $black);
                         $white = ImageColorAllocate($im, 255, 255, 255);
                         imagestring($im, 1, 1, 1, $user, $white);
                     }
                     $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_group.gif');
                     if ($ol_im < 0) {
                         return $iconfile;
                     }
                     self::imagecopyresized($im, $ol_im, 0, 0, 0, 0, imagesx($ol_im), imagesy($ol_im), imagesx($ol_im), imagesy($ol_im));
                 }
                 // Applying overlay based on mode:
                 if ($mode) {
                     unset($ol_im);
                     switch ($mode) {
                         case 'deleted':
                             $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_deleted.gif');
                             break;
                         case 'futuretiming':
                             $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_timing.gif');
                             break;
                         case 'timing':
                             $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_timing.gif');
                             break;
                         case 'hiddentiming':
                             $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_hidden_timing.gif');
                             break;
                         case 'no_icon_found':
                             $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_no_icon_found.gif');
                             break;
                         case 'disabled':
                             // is already greyed - nothing more
                             $ol_im = 0;
                             break;
                         case 'hidden':
                         default:
                             $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_hidden.gif');
                     }
                     if ($ol_im < 0) {
                         return $iconfile;
                     }
                     if ($ol_im) {
                         self::imagecopyresized($im, $ol_im, 0, 0, 0, 0, imagesx($ol_im), imagesy($ol_im), imagesx($ol_im), imagesy($ol_im));
                     }
                 }
                 // Protect-section icon:
                 if ($protectSection) {
                     $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_sub5.gif');
                     if ($ol_im < 0) {
                         return $iconfile;
                     }
                     self::imagecopyresized($im, $ol_im, 0, 0, 0, 0, imagesx($ol_im), imagesy($ol_im), imagesx($ol_im), imagesy($ol_im));
                 }
                 // Create the image as file, destroy GD image and return:
                 @self::imagemake($im, $path);
                 GeneralUtility::gif_compress($path, 'IM');
                 ImageDestroy($im);
                 return $mainpath;
             } else {
                 return $iconfile;
             }
         } else {
             return $GLOBALS['BACK_PATH'] . 'gfx/fileicons/default.gif';
         }
     }
 }
コード例 #4
0
ファイル: phpthumb.class.php プロジェクト: alanhaggai/plogger
 function Rotate()
 {
     if ($this->ra || $this->ar) {
         if (!function_exists('ImageRotate')) {
             $this->DebugMessage('!function_exists(ImageRotate)', __FILE__, __LINE__);
             return false;
         }
         if (!(include_once dirname(__FILE__) . '/phpthumb.filters.php')) {
             $this->DebugMessage('Error including "' . dirname(__FILE__) . '/phpthumb.filters.php" which is required for applying filters (' . implode(';', $this->fltr) . ')', __FILE__, __LINE__);
             return false;
         }
         $this->config_background_hexcolor = $this->bg ? $this->bg : $this->config_background_hexcolor;
         if (!phpthumb_functions::IsHexColor($this->config_background_hexcolor)) {
             return $this->ErrorImage('Invalid hex color string "' . $this->config_background_hexcolor . '" for parameter "bg"');
         }
         $rotate_angle = 0;
         if ($this->ra) {
             $rotate_angle = floatval($this->ra);
         } else {
             if ($this->ar == 'x') {
                 if (phpthumb_functions::version_compare_replacement(phpversion(), '4.2.0', '>=')) {
                     if ($this->sourceFilename) {
                         if (function_exists('exif_read_data')) {
                             if ($exif_data = @exif_read_data($this->sourceFilename, 'IFD0')) {
                                 // http://sylvana.net/jpegcrop/exif_orientation.html
                                 switch (@$exif_data['Orientation']) {
                                     case 1:
                                         $rotate_angle = 0;
                                         break;
                                     case 3:
                                         $rotate_angle = 180;
                                         break;
                                     case 6:
                                         $rotate_angle = 270;
                                         break;
                                     case 8:
                                         $rotate_angle = 90;
                                         break;
                                     default:
                                         $this->DebugMessage('EXIF auto-rotate failed because unknown $exif_data[Orientation] "' . @$exif_data['Orientation'] . '"', __FILE__, __LINE__);
                                         return false;
                                         break;
                                 }
                                 $this->DebugMessage('EXIF auto-rotate set to ' . $rotate_angle . ' degrees ($exif_data[Orientation] = "' . @$exif_data['Orientation'] . '")', __FILE__, __LINE__);
                             } else {
                                 $this->DebugMessage('failed: exif_read_data(' . $this->sourceFilename . ')', __FILE__, __LINE__);
                                 return false;
                             }
                         } else {
                             $this->DebugMessage('!function_exists(exif_read_data)', __FILE__, __LINE__);
                             return false;
                         }
                     } else {
                         $this->DebugMessage('Cannot auto-rotate from EXIF data because $this->sourceFilename is empty', __FILE__, __LINE__);
                         return false;
                     }
                 } else {
                     $this->DebugMessage('Cannot auto-rotate from EXIF data because PHP is less than v4.2.0 (' . phpversion() . ')', __FILE__, __LINE__);
                     return false;
                 }
             } elseif ($this->ar == 'l' && $this->source_height > $this->source_width) {
                 $rotate_angle = 270;
             } elseif ($this->ar == 'L' && $this->source_height > $this->source_width) {
                 $rotate_angle = 90;
             } elseif ($this->ar == 'p' && $this->source_width > $this->source_height) {
                 $rotate_angle = 90;
             } elseif ($this->ar == 'P' && $this->source_width > $this->source_height) {
                 $rotate_angle = 270;
             }
         }
         while ($rotate_angle < 0) {
             $rotate_angle += 360;
         }
         $rotate_angle = $rotate_angle % 360;
         if ($rotate_angle != 0) {
             $background_color = phpthumb_functions::ImageHexColorAllocate($this->gdimg_source, $this->config_background_hexcolor);
             if (phpthumb_functions::gd_version() >= 2 && $this->thumbnailFormat == 'png' && !$this->bg && $rotate_angle % 90) {
                 if ($gdimg_rotate_mask = phpthumb_functions::ImageCreateFunction(ImageSX($this->gdimg_source), ImageSY($this->gdimg_source))) {
                     $this->gdimg_source = ImageRotate($this->gdimg_source, $rotate_angle, $background_color);
                     $color_mask_opaque = ImageColorAllocate($gdimg_rotate_mask, 0xff, 0xff, 0xff);
                     $color_mask_transparent = ImageColorAllocate($gdimg_rotate_mask, 0x0, 0x0, 0x0);
                     ImageFilledRectangle($gdimg_rotate_mask, 0, 0, ImageSX($gdimg_rotate_mask), ImageSY($gdimg_rotate_mask), $color_mask_opaque);
                     $gdimg_rotate_mask = ImageRotate($gdimg_rotate_mask, $rotate_angle, $color_mask_transparent);
                     ImageAlphaBlending($this->gdimg_source, false);
                     if (phpthumb_functions::version_compare_replacement(phpversion(), '4.3.2', '>=')) {
                         ImageSaveAlpha($this->gdimg_source, true);
                     }
                     $this->is_alpha = true;
                     phpthumb_filters::ApplyMask($gdimg_rotate_mask, $this->gdimg_source);
                     ImageDestroy($gdimg_rotate_mask);
                     $this->source_width = ImageSX($this->gdimg_source);
                     $this->source_height = ImageSY($this->gdimg_source);
                 } else {
                     $this->DebugMessage('ImageCreateFromStringReplacement() failed for "' . $MaskFilename . '"', __FILE__, __LINE__);
                 }
             } else {
                 if (phpthumb_functions::gd_version() >= 2) {
                     $this->DebugMessage('Using non-alpha rotate because gd_version is "' . phpthumb_functions::gd_version() . '"', __FILE__, __LINE__);
                 } else {
                     $this->DebugMessage('Using non-alpha rotate because $this->thumbnailFormat is "' . $this->thumbnailFormat . '"', __FILE__, __LINE__);
                 }
                 if (ImageColorTransparent($this->gdimg_source) >= 0) {
                     // ImageRotate() forgets all about an image's transparency and sets the transparent color to black
                     // To compensate, flood-fill the transparent color of the source image with the specified background color first
                     // then rotate and the colors should match
                     if (!function_exists('ImageIsTrueColor') || !ImageIsTrueColor($this->gdimg_source)) {
                         // convert paletted image to true-color before rotating to prevent nasty aliasing artifacts
                         $this->source_width = ImageSX($this->gdimg_source);
                         $this->source_height = ImageSY($this->gdimg_source);
                         $gdimg_newsrc = phpthumb_functions::ImageCreateFunction($this->source_width, $this->source_height);
                         $background_color = phpthumb_functions::ImageHexColorAllocate($gdimg_newsrc, $this->config_background_hexcolor);
                         ImageFilledRectangle($gdimg_newsrc, 0, 0, $this->source_width, $this->source_height, phpthumb_functions::ImageHexColorAllocate($gdimg_newsrc, $this->config_background_hexcolor));
                         ImageCopy($gdimg_newsrc, $this->gdimg_source, 0, 0, 0, 0, $this->source_width, $this->source_height);
                         ImageDestroy($this->gdimg_source);
                         unset($this->gdimg_source);
                         $this->gdimg_source = $gdimg_newsrc;
                         unset($gdimg_newsrc);
                     } else {
                         ImageColorSet($this->gdimg_source, ImageColorTransparent($this->gdimg_source), hexdec(substr($this->config_background_hexcolor, 0, 2)), hexdec(substr($this->config_background_hexcolor, 2, 2)), hexdec(substr($this->config_background_hexcolor, 4, 2)));
                         ImageColorTransparent($this->gdimg_source, -1);
                     }
                 }
                 $this->gdimg_source = ImageRotate($this->gdimg_source, $rotate_angle, $background_color);
                 $this->source_width = ImageSX($this->gdimg_source);
                 $this->source_height = ImageSY($this->gdimg_source);
             }
         }
     }
     return true;
 }
コード例 #5
0
 function Rotate()
 {
     if (!function_exists('ImageRotate')) {
         return false;
     }
     if (!empty($this->ra) || !empty($this->ar)) {
         $this->config_background_hexcolor = !empty($this->bg) ? $this->bg : $this->config_background_hexcolor;
         if (!eregi('^[0-9A-F]{6}$', $this->config_background_hexcolor)) {
             $this->ErrorImage('Invalid hex color string "' . $this->config_background_hexcolor . '" for parameter "bg"');
         }
         $rotate_angle = 0;
         if (!empty($this->ra)) {
             $rotate_angle = floatval($this->ra);
         } else {
             if ($this->ar == 'l' && $this->source_height > $this->source_width) {
                 $rotate_angle = 270;
             } elseif ($this->ar == 'L' && $this->source_height > $this->source_width) {
                 $rotate_angle = 90;
             } elseif ($this->ar == 'p' && $this->source_width > $this->source_height) {
                 $rotate_angle = 90;
             } elseif ($this->ar == 'P' && $this->source_width > $this->source_height) {
                 $rotate_angle = 270;
             }
         }
         while ($rotate_angle < 0) {
             $rotate_angle += 360;
         }
         $rotate_angle = $rotate_angle % 360;
         if ($rotate_angle != 0) {
             if (ImageColorTransparent($this->gdimg_source) >= 0) {
                 // ImageRotate() forgets all about an image's transparency and sets the transparent color to black
                 // To compensate, flood-fill the transparent color of the source image with the specified background color first
                 // then rotate and the colors should match
                 if (!function_exists('ImageIsTrueColor') || !ImageIsTrueColor($this->gdimg_source)) {
                     // convert paletted image to true-color before rotating to prevent nasty aliasing artifacts
                     $this->source_width = ImageSX($this->gdimg_source);
                     $this->source_height = ImageSY($this->gdimg_source);
                     $gdimg_newsrc = $this->ImageCreateFunction($this->source_width, $this->source_height);
                     $background_color = phpthumb_functions::ImageHexColorAllocate($gdimg_newsrc, $this->config_background_hexcolor);
                     ImageFilledRectangle($gdimg_newsrc, 0, 0, $this->source_width, $this->source_height, phpthumb_functions::ImageHexColorAllocate($gdimg_newsrc, $this->config_background_hexcolor));
                     ImageCopy($gdimg_newsrc, $this->gdimg_source, 0, 0, 0, 0, $this->source_width, $this->source_height);
                     ImageDestroy($this->gdimg_source);
                     unset($this->gdimg_source);
                     $this->gdimg_source = $gdimg_newsrc;
                     unset($gdimg_newsrc);
                 } else {
                     ImageColorSet($this->gdimg_source, ImageColorTransparent($this->gdimg_source), hexdec(substr($this->config_background_hexcolor, 0, 2)), hexdec(substr($this->config_background_hexcolor, 2, 2)), hexdec(substr($this->config_background_hexcolor, 4, 2)));
                     ImageColorTransparent($this->gdimg_source, -1);
                 }
             }
             $background_color = phpthumb_functions::ImageHexColorAllocate($this->gdimg_source, $this->config_background_hexcolor);
             $this->gdimg_source = ImageRotate($this->gdimg_source, $rotate_angle, $background_color);
             $this->source_width = ImageSX($this->gdimg_source);
             $this->source_height = ImageSY($this->gdimg_source);
         }
     }
     return true;
 }
コード例 #6
0
 /**
  * Apply input levels to input image pointer (increasing contrast)
  *
  * @param integer $im GDlib Image Pointer
  * @param integer $low The "low" value (close to 0)
  * @param integer $high The "high" value (close to 255)
  * @param boolean $swap If swap, then low and high are swapped. (Useful for negated masks...)
  * @return void
  * @todo Define visibility
  */
 public function inputLevels(&$im, $low, $high, $swap = '')
 {
     if ($low < $high) {
         $low = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($low, 0, 255);
         $high = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($high, 0, 255);
         if ($swap) {
             $temp = $low;
             $low = 255 - $high;
             $high = 255 - $temp;
         }
         $delta = $high - $low;
         $totalCols = ImageColorsTotal($im);
         for ($c = 0; $c < $totalCols; $c++) {
             $cols = ImageColorsForIndex($im, $c);
             $cols['red'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange(($cols['red'] - $low) / $delta * 255, 0, 255);
             $cols['green'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange(($cols['green'] - $low) / $delta * 255, 0, 255);
             $cols['blue'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange(($cols['blue'] - $low) / $delta * 255, 0, 255);
             ImageColorSet($im, $c, $cols['red'], $cols['green'], $cols['blue']);
         }
     }
 }
コード例 #7
0
 /**
  * Apply input levels to input image pointer (increasing contrast)
  *
  * @param	integer		GDlib Image Pointer
  * @param	integer		The "low" value (close to 0)
  * @param	integer		The "high" value (close to 255)
  * @param	boolean		If swap, then low and high are swapped. (Useful for negated masks...)
  * @return	void
  */
 function inputLevels(&$im, $low, $high, $swap = '')
 {
     if ($low < $high) {
         $low = t3lib_div::intInRange($low, 0, 255);
         $high = t3lib_div::intInRange($high, 0, 255);
         if ($swap) {
             $temp = $low;
             $low = 255 - $high;
             $high = 255 - $temp;
         }
         $delta = $high - $low;
         $totalCols = ImageColorsTotal($im);
         for ($c = 0; $c < $totalCols; $c++) {
             $cols = ImageColorsForIndex($im, $c);
             $cols['red'] = t3lib_div::intInRange(($cols['red'] - $low) / $delta * 255, 0, 255);
             $cols['green'] = t3lib_div::intInRange(($cols['green'] - $low) / $delta * 255, 0, 255);
             $cols['blue'] = t3lib_div::intInRange(($cols['blue'] - $low) / $delta * 255, 0, 255);
             ImageColorSet($im, $c, $cols['red'], $cols['green'], $cols['blue']);
         }
     }
 }
コード例 #8
0
ファイル: status.php プロジェクト: StapleButter/jul
function fontc($r1, $g1, $b1, $r2, $g2, $b2, $r3, $g3, $b3)
{
    $font = ImageCreateFromPNG('images/rpg/font.png');
    ImageColorTransparent($font, 1);
    ImageColorSet($font, 6, $r1, $g1, $b1);
    ImageColorSet($font, 5, ($r1 * 2 + $r2) / 3, ($g1 * 2 + $g2) / 3, ($b1 * 2 + $b2) / 3);
    ImageColorSet($font, 4, ($r1 + $r2 * 2) / 3, ($g1 + $g2 * 2) / 3, ($b1 + $b2 * 2) / 3);
    ImageColorSet($font, 3, $r2, $g2, $b2);
    ImageColorSet($font, 0, $r3, $g3, $b3);
    return $font;
}
コード例 #9
0
 public function build_sw($imgn, $watermark, $logo_pagarm)
 {
     $watermark = $this->resizeImage($watermark, 60, 80, 'test', 'jpg');
     imagetruecolortopalette($watermark, false, 256);
     $white = imagecolorexact($watermark, 252, 254, 252);
     $tmp = imagerotate($watermark, $logo_pagarm[0], $white);
     if ($tmp) {
         $watermark = imagerotate($watermark, $logo_pagarm[0], $white);
         imagetruecolortopalette($watermark, false, 256);
         $white = imagecolorexact($watermark, 252, 254, 252);
         imagedestroy($tmp);
     } else {
         $white = $this->imagegetcolor($watermark, 252, 254, 252);
         $watermark = imagerotate($watermark, $logo_pagarm[0], $white);
         imagetruecolortopalette($watermark, false, 256);
         $white = $this->imagegetcolor($watermark, 252, 254, 252);
     }
     imagecolortransparent($watermark, $white);
     ImageColorSet($watermark, $white, 0, 0, 0);
     $w_x = imagesx($watermark);
     $w_y = imagesy($watermark);
     imagecopymerge($imgn, $watermark, $logo_pagarm[1], $logo_pagarm[2], 0, 0, $w_x, $w_y, 100);
     //imagegif($imgn,WWW_ROOT.'img'.DS.'ytmpfile.gif');
     return $imgn;
     //imagepng($watermark,WWW_ROOT.'img'.DS.'xtmpfile.png');
 }
コード例 #10
0
function render_global($game_id)
{
    global $UNI, $systems, $preview, $loc, $exp_sys, $random_filename, $gen_new_maps, $directories;
    $size_x = $UNI['size_x'] + $UNI['map_border'] * 2;
    $size_y = $UNI['size_y'] + $UNI['map_border'] * 2;
    $offset_x = $UNI['map_border'];
    $offset_y = $UNI['map_border'];
    $central_star = 1;
    //this star is the hub of the universe.
    $uv_show_warp_numbers = get_db_var('uv_show_warp_numbers');
    $numsize = $UNI['num_size'];
    $im = imagecreatetruecolor($size_x, $size_y);
    $earthIm = imagecreatefrompng($directories['images'] . '/map/earth.png');
    $earthDim = array(imagesx($earthIm), imagesy($earthIm));
    $earthPos = array(-$earthDim[0] / 2, -$earthDim[1] / 2);
    $starIm = imagecreatefrompng($directories['images'] . '/map/star.png');
    $starDim = array(imagesx($starIm), imagesy($starIm));
    $starPos = array(-$starDim[0] / 2, -$starDim[1] / 2);
    //allocate the colours
    $color_bg = ImageColorAllocate($im, $UNI['bg_color'][0], $UNI['bg_color'][1], $UNI['bg_color'][2]);
    $color_st = ImageColorAllocate($im, $UNI['num_color'][0], $UNI['num_color'][1], $UNI['num_color'][2]);
    $color_sd = ImageColorAllocate($im, $UNI['star_color'][0], $UNI['star_color'][1], $UNI['star_color'][2]);
    $color_sl = ImageColorAllocate($im, $UNI['link_color'][0], $UNI['link_color'][1], $UNI['link_color'][2]);
    $color_sh = ImageColorAllocate($im, $UNI['num_color3'][0], $UNI['num_color3'][1], $UNI['num_color3'][2]);
    $color_l = ImageColorAllocate($im, $UNI['label_color'][0], $UNI['label_color'][1], $UNI['label_color'][2]);
    $worm_1way_color = ImageColorAllocate($im, $UNI['worm_one_way_color'][0], $UNI['worm_one_way_color'][1], $UNI['worm_one_way_color'][2]);
    $worm_2way_color = ImageColorAllocate($im, $UNI['worm_two_way_color'][0], $UNI['worm_two_way_color'][1], $UNI['worm_two_way_color'][2]);
    //get the star systems from the Db if using pre-genned map.
    if (isset($gen_new_maps)) {
        db("select (star_id -1) as num, x_loc, y_loc, wormhole, CONCAT(link_1 -1, ',', link_2 -1, ',', link_3 -1, ',', link_4 -1, ',', link_5 -1, ',', link_6 -1) as links from {$game_id}_stars order by star_id asc");
        while ($systems[] = dbr(1)) {
        }
        //dump all entries into $systems.
        unset($systems[count($systems) - 1]);
        //remove a surplus entry
    }
    //process stars
    foreach ($systems as $star) {
        if (!empty($star['links'])) {
            //don't link all systems to 1 automatically.
            $star_links = array_map("plus_one", explode(',', $star['links']));
            $star_id = $star['num'] + 1;
            foreach ($star_links as $link) {
                //make star links
                if ($link < 1) {
                    continue 1;
                }
                $other_star = $systems[$link - 1];
                //set other_star to the link destination.
                imageline($im, $star['x_loc'] + $offset_x, $star['y_loc'] + $offset_y, $other_star['x_loc'] + $offset_x, $other_star['y_loc'] + $offset_y, $color_sl);
            }
        }
        if (!empty($star['wormhole'])) {
            //Wormhole Manipulation
            $other_star = $systems[$star['wormhole'] - 1];
            if ($other_star['wormhole'] == $star_id) {
                //two way
                imageline($im, $star['x_loc'] + $offset_x, $star['y_loc'] + $offset_y, $other_star['x_loc'] + $offset_x, $other_star['y_loc'] + $offset_y, $worm_2way_color);
            } else {
                //one way
                imageline($im, $star['x_loc'] + $offset_x, $star['y_loc'] + $offset_y, $other_star['x_loc'] + $offset_x, $other_star['y_loc'] + $offset_y, $worm_1way_color);
            }
        }
    }
    $central_star = 0;
    //hack to take into account arrays start with 0.
    foreach ($systems as $star) {
        //place the star itself. This is done after the lines, so the text comes on top.
        $off = array(-5, 4);
        //offset of text from star location
        if ($star['num'] == $central_star) {
            imagecopy($im, $earthIm, $star['x_loc'] + $offset_x + $earthPos[0], $star['y_loc'] + $offset_y + $earthPos[1], 0, 0, $earthDim[0], $earthDim[1]);
        } else {
            imagecopy($im, $starIm, $star['x_loc'] + $offset_x + $starPos[0], $star['y_loc'] + $offset_y + $starPos[1], 0, 0, $starDim[0], $starDim[1]);
        }
        //only show warp numbers if admin wants them.
        if ($uv_show_warp_numbers == 1) {
            if ($central_star === $star['num']) {
                $off = array(-5, 9);
                //write the star number under the star
                imagestring($im, $UNI['num_size'] + 2, $star['x_loc'] + $offset_x + $off[0], $star['y_loc'] + $offset_y + $off[1], $star['num'] + 1, $color_st);
            } else {
                imagestring($im, $UNI['num_size'], $star['x_loc'] + $offset_x + $off[0], $star['y_loc'] + $offset_y + $off[1], $star['num'] + 1, $color_st);
            }
        }
    }
    //for just a preview we can quit while we're ahead.
    if (isset($preview)) {
        Header("Content-type: image/png");
        ImagePng($im);
        ImageDestroy($im);
        exit;
    }
    //Draw title centered on the horizontal
    imagestring($im, 5, $size_x / 2 - 80, 5, "Universal Star Map", $color_l);
    //Create buffer image
    $bb_im = imagecreatetruecolor($UNI['size_x'] + $UNI['localmapwidth'], $UNI['size_y'] + $UNI['localmapheight']);
    ImageColorAllocate($im, $UNI['bg_color'][0], $UNI['bg_color'][1], $UNI['bg_color'][2]);
    ImageCopy($bb_im, $im, $UNI['localmapwidth'] / 2, $UNI['localmapheight'] / 2, $offset_x, $offset_y, $size_x, $size_y);
    //Create printable map
    $p_im = imagecreatetruecolor($size_x, $size_y);
    ImageColorAllocate($p_im, $UNI['print_bg_color'][0], $UNI['print_bg_color'][1], $UNI['print_bg_color'][2]);
    ImageCopy($p_im, $im, 0, 0, 0, 0, $size_x, $size_y);
    //Replace colors
    $index = ImageColorExact($p_im, $UNI['bg_color'][0], $UNI['bg_color'][1], $UNI['bg_color'][2]);
    ImageColorSet($p_im, $index, $UNI['print_bg_color'][0], $UNI['print_bg_color'][1], $UNI['print_bg_color'][2]);
    $index = ImageColorExact($p_im, $UNI['link_color'][0], $UNI['link_color'][1], $UNI['link_color'][2]);
    ImageColorSet($p_im, $index, $UNI['print_link_color'][0], $UNI['print_link_color'][1], $UNI['print_link_color'][2]);
    $index = ImageColorExact($p_im, $UNI['num_color'][0], $UNI['num_color'][1], $UNI['num_color'][2]);
    ImageColorSet($p_im, $index, $UNI['print_num_color'][0], $UNI['print_num_color'][1], $UNI['print_num_color'][2]);
    $index = ImageColorExact($p_im, $UNI['num_color3'][0], $UNI['num_color3'][1], $UNI['num_color3'][2]);
    ImageColorSet($p_im, $index, $UNI['print_num_color'][0], $UNI['print_num_color'][1], $UNI['print_num_color'][2]);
    $index = ImageColorExact($p_im, $UNI['star_color'][0], $UNI['star_color'][1], $UNI['star_color'][2]);
    ImageColorSet($p_im, $index, $UNI['print_star_color'][0], $UNI['print_star_color'][1], $UNI['print_star_color'][2]);
    //Draw new label
    ImageFilledRectangle($p_im, 0, 0, $size_x, $UNI['map_border'], ImageColorExact($p_im, $UNI['print_bg_color'][0], $UNI['print_bg_color'][1], $UNI['print_bg_color'][2]));
    imagestring($p_im, 5, $size_x / 2 - 80, 5, "Printable Star Map", ImageColorExact($p_im, $UNI['print_label_color'][0], $UNI['print_label_color'][1], $UNI['print_label_color'][2]));
    //get random filename. primarily for it re-genning maps.
    if (empty($random_filename)) {
        db("select random_filename from se_games where db_name = '{$game_id}'");
        $temp_filename = dbr(1);
        $random_filename = $temp_filename['random_filename'];
    }
    //Save map and finish
    ImagePng($im, "{$directories['images']}/{$game_id}_maps/sm_full_{$random_filename}.png");
    ImageDestroy($im);
    ImagePng($bb_im, "{$directories['images']}/{$game_id}_maps/bb_full_{$random_filename}.png");
    ImageDestroy($bb_im);
    ImagePng($p_im, "{$directories['images']}/{$game_id}_maps/psm_full_{$random_filename}.png");
    ImageDestroy($p_im);
}
コード例 #11
0
ファイル: image.php プロジェクト: anti-conformiste/thelia1
function traiter_image($nomorig, $dest_width, $dest_height, $opacite, $nb, $miroir, $exact, $couleurfond, &$type)
{
    list($width_orig, $height_orig, $type, $attr) = getimagesize($nomorig);
    if (!$width_orig) {
        return false;
    }
    if ($dest_width == NULL) {
        $dest_width = $width_orig;
    }
    if ($dest_height == NULL) {
        $dest_height = $height_orig;
    }
    $width_diff = $dest_width / $width_orig;
    $height_diff = $dest_height / $height_orig;
    $delta_x = $delta_y = $border_width = $border_height = 0;
    if ($width_diff > 1 and $height_diff > 1) {
        $next_width = $width_orig;
        $next_height = $height_orig;
        $dest_width = intval($exact) == 1 ? $dest_width : $next_width;
        $dest_height = intval($exact) == 1 ? $dest_height : $next_height;
    } else {
        if ($width_diff > $height_diff) {
            $next_height = $dest_height;
            $next_width = intval($width_orig * $next_height / $height_orig);
            if ($exact == IMAGE_REDIM_RECADRE) {
                $dest_ratio = $dest_width / $width_orig;
                $ho = $dest_height / $dest_ratio;
                $delta_y = ($height_orig - $ho) / 2;
                $height_orig = $ho;
                $next_width = $dest_width;
            } else {
                if ($exact != IMAGE_REDIM_BORDURE) {
                    $dest_width = $next_width;
                }
            }
        } else {
            $next_width = $dest_width;
            $next_height = intval($height_orig * $dest_width / $width_orig);
            if ($exact == IMAGE_REDIM_RECADRE) {
                $dest_ratio = $dest_height / $height_orig;
                $wo = $dest_width / $dest_ratio;
                $delta_x = ($width_orig - $wo) / 2;
                $width_orig = $wo;
                $next_height = $dest_height;
            } else {
                if ($exact != IMAGE_REDIM_BORDURE) {
                    $dest_height = $next_height;
                }
            }
        }
    }
    if ($exact == IMAGE_REDIM_BORDURE) {
        $border_width = intval(($dest_width - $next_width) / 2);
        $border_height = intval(($dest_height - $next_height) / 2);
    }
    $image_new = imagecreatetruecolor($dest_width, $dest_height);
    switch ($type) {
        case IMAGETYPE_GIF:
            $image_orig = imagecreatefromgif($nomorig);
            break;
        case IMAGETYPE_JPEG:
        default:
            $image_orig = imagecreatefromjpeg($nomorig);
            break;
        case IMAGETYPE_PNG:
            $image_orig = imagecreatefrompng($nomorig);
            break;
    }
    // Preparer la couleur de fond (pour bordures, transparence, miroir)
    if ($couleurfond == '') {
        $couleurfond = 'ffffff';
    }
    $fondrgb = hex2RGB($couleurfond);
    // Définir la couleur de fond générale
    $bgcolor = imagecolorallocate($image_new, $fondrgb['red'], $fondrgb['green'], $fondrgb['blue']);
    // Préserver la transparence des gifs et png
    if ($type != IMAGETYPE_JPEG) {
        $trnprt_indx = imagecolortransparent($image_orig);
        // If we have a specific transparent color
        if ($trnprt_indx >= 0) {
            // Get the original image's transparent color's RGB values
            $trnprt_color = imagecolorsforindex($image_orig, $trnprt_indx);
            // Allocate the same color in the new image resource
            $trnprt_indx = imagecolorallocate($image_new, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
            // Completely fill the background of the new image with allocated color.
            imagefill($image_new, 0, 0, $trnprt_indx);
            // Set the background color for new image to transparent
            imagecolortransparent($image_new, $trnprt_indx);
        } else {
            // Turn off transparency blending (temporarily)
            imagealphablending($image_new, false);
            // Create a new transparent color for image
            $color = imagecolorallocatealpha($image_new, 0, 0, 0, 127);
            // Completely fill the background of the new image with allocated color.
            imagefill($image_new, 0, 0, $color);
            // Restore transparency blending
            imagesavealpha($image_new, true);
            // Remplir avec la couleur de fond
            imagefill($image_new, 0, 0, $bgcolor);
        }
    } else {
        // Remplir avec la couleur de fond
        imagefill($image_new, 0, 0, $bgcolor);
    }
    if ($opacite != "") {
        $opac_img = imagecreatetruecolor($width_orig, $height_orig);
        imagefill($opac_img, 0, 0, $bgcolor);
        imagecopymerge($opac_img, $image_orig, 0, 0, 0, 0, $width_orig, $height_orig, $opacite);
        $image_orig = $opac_img;
    }
    // Redimensionnement, avec ajout éventuel de bordures.
    imagecopyresampled($image_new, $image_orig, $border_width, $border_height, $delta_x, $delta_y, $next_width, $next_height, $width_orig, $height_orig);
    // Noir et blanc
    if ($nb != "") {
        imagetruecolortopalette($image_new, false, 256);
        $total = ImageColorsTotal($image_new);
        for ($i = 0; $i < $total; $i++) {
            $old = ImageColorsForIndex($image_new, $i);
            $commongrey = (int) (($old['red'] + $old['green'] + $old['blue']) / 3);
            ImageColorSet($image_new, $i, $commongrey, $commongrey, $commongrey);
        }
    }
    if ($miroir != "") {
        $mh = intval($miroir) == 1 ? 50 : intval($miroir);
        $largeur = imagesx($image_new);
        $hauteur = imagesy($image_new);
        $temporaireUn = imagecreatetruecolor($largeur, $mh);
        $temporaireDeux = imagecreatetruecolor($largeur, $mh);
        $resultat = imagecreatetruecolor($largeur, $hauteur + $mh);
        imagefill($resultat, 1, 1, $bgcolor);
        imagefill($temporaireDeux, 1, 1, $bgcolor);
        imagecopy($resultat, $image_new, 0, 0, 0, 0, $largeur, $hauteur);
        imagecopy($temporaireUn, $image_new, 0, 0, 0, $hauteur - $mh, $largeur, $mh);
        effet_miroir($temporaireDeux, $temporaireUn);
        imagecopy($resultat, $temporaireDeux, 0, $hauteur, 0, 0, $largeur, $mh);
        $image_new = $resultat;
    }
    return $image_new;
}
コード例 #12
0
 /**
  * Desaturates an image, id optional $shade variable = 0 then image will be grey scale, 1 = red, 2 = greem 3 = blue
  *
  * NOTE: By adjusting the weight array prior to desaturating the image you can split the channels of an image.
  *
  * @param integer $shade What colour to shade the image
  * @return boolean Whether it was sucessful
  * @access public
  */
 function desaturate($shade = 0)
 {
     if (!$this->im) {
         return false;
     }
     //convert o,age to 256 colours
     ImageTrueColorToPalette($this->im, 1, 256);
     //calculate total number of colours in palette
     $total = ImageColorsTotal($this->im);
     //for each colour make it grey
     for ($i = 0; $i < $total; $i++) {
         $old = ImageColorsForIndex($this->im, $i);
         //get correct colouring by performing a weighted average of the 3
         $grey = round(($this->gamma[0] * $old["red"] + $this->gamma[1] * $old["green"] + $this->gamma[2] * $old["blue"]) / 3);
         if ($shade == 1) {
             ImageColorSet($this->im, $i, $grey, 0, 0);
         } else {
             if ($shade == 2) {
                 ImageColorSet($this->im, $i, 0, $grey, 0);
             } else {
                 if ($shade == 3) {
                     ImageColorSet($this->im, $i, 0, 0, $grey);
                 } else {
                     ImageColorSet($this->im, $i, $grey, $grey, $grey);
                 }
             }
         }
     }
     return true;
 }