Guest User

Untitled

a guest
May 22nd, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.19 KB | None | 0 0
  1. <?php
  2.  
  3. $mimetypes = array(
  4.     'image/jpeg' => 'jpeg',
  5.     'image/png' => 'png',
  6.     'image/gif' => 'gif',
  7. );
  8.  
  9. function createimage($filename, $mime) {
  10.     global $mimetypes;
  11.     $mime = trim($mime);
  12.    
  13.     if (isset($mimetypes[$mime])) {
  14.         $imagecreate = 'imagecreatefrom' . $mimetypes[$mime];
  15.         return $imagecreate($filename);
  16.     }
  17. }
  18.  
  19. function displayimage($image, $mime) {
  20.     global $mimetypes;
  21.     $mime = trim($mime);
  22.    
  23.     if (isset($mimetypes[$mime])) {
  24.         header('Content-Type: ' . $mime);
  25.         $img = 'image' . $mimetypes[$mime];
  26.         return $img($image);
  27.     }
  28. }
  29.  
  30. function getpixelarray($image, $width, $height) {
  31.     $pixels = array();
  32.     for ($y = 0; $y < $height; $y++) {
  33.         for ($x = 0; $x < $width; $x++) {
  34.             array_push($pixels, imagecolorat($image, $x, $y));
  35.         }
  36.     }
  37.     return $pixels;
  38. }
  39.  
  40. function applypixels($image, $pixels, $x, $y, $width, $height, $opacity) {
  41.     /**
  42.      *  formula for finding posistion in pixel array
  43.      *
  44.      *  x + (y * width)
  45.      */
  46.     $trans = 256 - $opacity;
  47.     for ($y1 = $y; $y1 < $height; $y1++) {
  48.         for ($x1 = $x; $x1 < $width; $x1++) {
  49.             $rgb = convertlong($pixels[$x1 + ($y1 * $width)]);
  50.             if ($rgb['r'] == $rgb['g'] && $rgb['g'] == $rgb['b']) {
  51.                
  52.             } else {
  53.                 $imgcol = imagecolorat($image, $x1, $y1);
  54.                 $wcol = convertlong($pixels[$x1 + ($y1 * $width)]);
  55.                
  56.                 $ir = ($imgcol >> 16 & 0xff) * $trans;
  57.                 $ig = ($imgcol >> 8 & 0xff) * $trans;
  58.                 $ib = ($imgcol & 0xff) * $trans;
  59.                
  60.                
  61.                 $color = (($wcol['r'] + $ir >> 8) << 16) + (($wcol['g'] + $ig >> 8) << 8)+ ($wcol['b'] + $ib >> 8);
  62.                 imagesetpixel($image, $x1, $y1, $color);
  63.                 //imagesetpixel($image, $x1, $y1, $pixels[$x1 + ($y1 * $width)]);
  64.             }
  65.         }
  66.     }
  67. }
  68.  
  69. function resizeimage($width, $height, $target) {
  70.     if ($width > $height) {
  71.         $percentage = ($target / $width);
  72.     } else {
  73.         $percentage = ($target / $height);
  74.     }
  75.     $width = round($width * $percentage);
  76.     $height = round($height * $percentage);
  77.     return 'width=' . $width . ' height=' . $height;
  78. }
  79.  
  80. function convertlong($long) {
  81.     return array(
  82.         'r' => ($long >> 16) & 255,
  83.         'g' =>($long >> 8) & 255,
  84.         'b' => $long & 255
  85.     );
  86. }
  87.  
  88. function convertarray($array) {
  89.     return ($array['r'] << 16) + ($array['g'] << 8) + $array['b'];
  90. }
  91.  
  92. ?>
Add Comment
Please, Sign In to add comment