Exemple #1
0
function createthumb($name, $filename, $new_w, $new_h)
{
    // $src_img=null;
    //$system=explode(".",$name);
    if (preg_match("/jpg|jpeg|JPG/", $name)) {
        $src_img = imagecreatefromjpeg($name);
    }
    if (preg_match("/png/", $name)) {
        $src_img = imagecreatefrompng($name);
    }
    if (preg_match("/gif/", $name)) {
        $src_img = imagecreatefromgif($name);
    }
    $old_x = imagesX($src_img);
    $old_y = imagesY($src_img);
    $thumb_w = (int) $new_w;
    $thumb_h = (int) $new_h;
    //$dst_img=imagecreate($thumb_w,$thumb_h);
    $dst_img = imagecreatetruecolor($thumb_w, $thumb_h);
    //imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
    imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
    if (preg_match("/png|PNG/", $name)) {
        imagepng($dst_img, $filename);
    } else {
        imagejpeg($dst_img, $filename, 100);
    }
    imagedestroy($dst_img);
    imagedestroy($src_img);
}
Exemple #2
0
 /**
  * Method to apply a background color to an image resource.
  *
  * @param   array  $options  An array of options for the filter.
  *                           color  Background matte color
  *
  * @return  void
  *
  * @since   3.4
  * @throws  InvalidArgumentException
  * @deprecated  5.0  Use Joomla\Image\Filter\Backgroundfill::execute() instead
  */
 public function execute(array $options = array())
 {
     // Validate that the color value exists and is an integer.
     if (!isset($options['color'])) {
         throw new InvalidArgumentException('No color value was given. Expected string or array.');
     }
     $colorCode = !empty($options['color']) ? $options['color'] : null;
     // Get resource dimensions
     $width = imagesX($this->handle);
     $height = imagesY($this->handle);
     // Sanitize color
     $rgba = $this->sanitizeColor($colorCode);
     // Enforce alpha on source image
     if (imageIsTrueColor($this->handle)) {
         imageAlphaBlending($this->handle, false);
         imageSaveAlpha($this->handle, true);
     }
     // Create background
     $bg = imageCreateTruecolor($width, $height);
     imageSaveAlpha($bg, empty($rgba['alpha']));
     // Allocate background color.
     $color = imageColorAllocateAlpha($bg, $rgba['red'], $rgba['green'], $rgba['blue'], $rgba['alpha']);
     // Fill background
     imageFill($bg, 0, 0, $color);
     // Apply image over background
     imageCopy($bg, $this->handle, 0, 0, 0, 0, $width, $height);
     // Move flattened result onto curent handle.
     // If handle was palette-based, it'll stay like that.
     imageCopy($this->handle, $bg, 0, 0, 0, 0, $width, $height);
     // Free up memory
     imageDestroy($bg);
     return;
 }
function generate_thumbnail($file, $mime)
{
    global $config;
    gd_capabilities();
    list($file_type, $exact_type) = explode("/", $mime);
    if (_JB_GD_INSTALLED && ($file_type = "image")) {
        if ($exact_type != "gif" && $exact_type != "png" && $exact_type != "jpeg") {
            return false;
        }
        if ($exact_type == "gif" && !_JB_GD_GIF) {
            return false;
        }
        if ($exact_type == "png" && !_JB_GD_PNG) {
            return false;
        }
        if ($exact_type == "jpeg" && !_JB_GD_JPG) {
            return false;
        }
        // Load up the original and get size
        //  NOTE: use imageCreateFromString to avoid to have to check what type of image it is
        $original = imageCreateFromString(file_get_contents($file));
        $original_w = imagesX($original);
        $original_h = imagesY($original);
        // Only if the image is really too big, resize it
        // NOTE: if image is smaller than target size, don't do anything.
        //  We *could* copy the original to filename_thumb, but since it's the same
        //  it would be a waste of precious resources
        if ($original_w > $config['uploader']['thumb_w'] || $original_h > $config['uploader']['thumb_h']) {
            // If original is wider than it's high, resize the width and vice versa
            // NOTE: '>=' cause otherwise it's possible that $scale isn't computed
            if ($original_w >= $original_h) {
                $scaled_w = $config['uploader']['thumb_w'];
                // Figure out how much smaller that target is than original
                //  and apply it to height
                $scale = $config['uploader']['thumb_w'] / $original_w;
                $scaled_h = ceil($original_h * $scale);
            } elseif ($original_w <= $original_h) {
                $scaled_h = $config['uploader']['thumb_h'];
                $scale = $config['uploader']['thumb_h'] / $original_h;
                $scaled_w = ceil($original_w * $scale);
            }
        } else {
            // Break out of if($file_type = image) since no resize is possible
            return false;
        }
        // Scale the image
        $scaled = imageCreateTrueColor($scaled_w, $scaled_h);
        imageCopyResampled($scaled, $original, 0, 0, 0, 0, $scaled_w, $scaled_h, $original_w, $original_h);
        // Store thumbs in jpeg, hope no one minds the 100% quality lol
        imageJpeg($scaled, $file . "_thumb", 100);
        // Let's be nice to our server
        imagedestroy($scaled);
        imagedestroy($original);
        return true;
    }
}
 function buildProfile()
 {
     $error = false;
     $this->facebook = $this->session->app->loadFacebookLibrary();
     try {
         $resp = $this->facebook->api_client->users_getInfo($this->session->fbId, 'pic,pic_big,pic_small,pic_square');
     } catch (Exception $e) {
         $this->db->log($e);
         $error = true;
     }
     include PATH_TEMPLATES . '/media.php';
     $profileUrl = $this->getLargestProfilePic($resp[0]);
     $proImage = imagecreatefromjpeg($profileUrl);
     $proX = imagesx($proImage);
     $proY = imagesY($proImage);
     $code .= $this->templateObj->templates['mediaProfileIntro'];
     $code .= '<div id="mediaPro_left">';
     $code .= $this->buildProfilePreview();
     $code .= '<!-- end leftside --></div>';
     $code .= '<div id="mediaPro_right">';
     if (count($imgList) > 1) {
         $code .= '<h3>Choose an image for your profile picture:</h3>';
     }
     $code .= '<div class="mediaGrid"><input type="hidden" value="' . count($imgList) . '" id="numProfileImages" />';
     $i = 0;
     foreach ($imgList as $thumb) {
         $code .= '<div class="thumb"><img id="proImage_' . $i . '" ' . ($i == 0 ? 'class="selected"' : '') . ' src="' . $imgList[$i] . '" alt="thumbnail of overlay" onclick="changeProfileImage(' . $i . ');"></div>';
         $i += 1;
     }
     $code .= '<!-- end gridBlock of images --></div><br />';
     $code .= $this->ajaxBuildProfileForm(0, $profileUrl);
     $code .= '<!-- end rightside --></div>';
     // URL_CALLBACK
     // build left side
     $code .= '<br clear="all" />' . $this->fetchLinkProfileBox($imgLinkTitle, $imgLinkCaption, $imgList);
     $code .= '<fb:js-string var="mediaAuthMsg">Please <a href="?p=media&o=pro" requirelogin="******">authorize ' . SITE_TITLE . '</a> with Facebook so you we can access your profile photo.</fb:js-string>';
     return $code;
 }
 /**
  * @param  resource $dstResource
  * @param  resource $srcResource
  * @param  int      $x
  * @param  int      $y
  * @param  string   $gravity
  * @return resource
  */
 public function getMergedGdResource($dstResource, $srcResource, $x = 0, $y = 0, $gravity = RegularLayerInterface::MOVE_TOP_LEFT, $opacity = 100)
 {
     $dstWidth = imagesx($dstResource);
     $dstHeight = imagesy($dstResource);
     $srcWidth = imagesx($srcResource);
     $srcHeight = imagesY($srcResource);
     switch ($gravity) {
         case RegularLayerInterface::MOVE_TOP_LEFT:
             $x += 0;
             $y += 0;
             break;
         case RegularLayerInterface::MOVE_TOP_CENTER:
             $x += round(($dstWidth - $srcWidth) / 2);
             $y += 0;
             break;
         case RegularLayerInterface::MOVE_TOP_RIGHT:
             $x += $dstWidth - $srcWidth;
             $y += 0;
             break;
         case RegularLayerInterface::MOVE_CENTER_LEFT:
             $x += 0;
             $y += round(($dstHeight - $srcHeight) / 2);
             break;
         case RegularLayerInterface::MOVE_CENTER:
             $x += round(($dstWidth - $srcWidth) / 2);
             $y += round(($dstHeight - $srcHeight) / 2);
             break;
         case RegularLayerInterface::MOVE_CENTER_RIGHT:
             $x += $dstWidth - $srcWidth;
             $y += round(($dstHeight - $srcHeight) / 2);
             break;
         case RegularLayerInterface::MOVE_BOTTOM_LEFT:
             $x += 0;
             $y += $dstHeight - $srcHeight;
             break;
         case RegularLayerInterface::MOVE_BOTTOM_CENTER:
             $x += round(($dstWidth - $srcWidth) / 2);
             $y += $dstHeight - $srcHeight;
             break;
         case RegularLayerInterface::MOVE_BOTTOM_RIGHT:
             $x += $dstWidth - $srcWidth;
             $y += $dstHeight - $srcHeight;
     }
     if ($x <= -$srcWidth || $x >= $dstWidth || $y <= -$srcHeight || $y >= $dstHeight) {
         return $dstResource;
     }
     if ($x <= 0) {
         $dstX = 0;
         $srcX = -$x;
         $srcW = min($srcWidth + $x, $dstWidth);
     } else {
         $dstX = $x;
         $srcX = 0;
         $srcW = min($dstWidth - $x, $srcWidth);
     }
     if ($y <= 0) {
         $dstY = 0;
         $srcY = -$y;
         $srcH = min($srcHeight + $y, $dstHeight);
     } else {
         $dstY = $y;
         $srcY = 0;
         $srcH = min($dstHeight - $y, $srcHeight);
     }
     if (!imageistruecolor($dstResource)) {
         $resource = $this->getEmptyGdResource($dstWidth, $dstHeight);
         imagecopy($resource, $dstResource, 0, 0, 0, 0, $dstWidth, $dstHeight);
         imagedestroy($dstResource);
         $dstResource = $resource;
     }
     $opacity = is_null($opacity) ? 100 : $opacity;
     imagecopymerge($dstResource, $srcResource, $dstX, $dstY, $srcX, $srcY, $srcW, $srcH, $opacity);
     return $dstResource;
 }
 public function resizeImage($dir, $toResize, $maxW = 750, $maxH = 540, $force = false)
 {
     $imagemToResize = $dir . $toResize;
     $ext = "." . end(explode(".", $toResize));
     $error = '';
     if (!$maxH && !$maxW) {
         return true;
     }
     $largura_alvo = $maxW;
     $altura_alvo = $maxH;
     if ($maxW <= $largura_alvo && $maxH <= $altura_alvo && ($force = false)) {
         return true;
     }
     $file_dimensions = getimagesize($dir . $toResize);
     $fileType = strtolower($file_dimensions['mime']);
     if ($fileType == 'image/jpeg' || $fileType == 'image/jpg' || $fileType == 'image/pjpeg') {
         $img = imagecreatefromjpeg($imagemToResize);
     } else {
         if ($fileType == 'image/png') {
             $img = imagecreatefrompng($imagemToResize);
         } else {
             if ($fileType == 'image/gif') {
                 $img = imagecreatefromgif($imagemToResize);
             }
         }
     }
     $largura_original = imagesX($img);
     $altura_original = imagesY($img);
     $altura_nova = $altura_original * $largura_alvo / $largura_original;
     if ($altura_nova > $altura_alvo) {
         $altura_nova = $altura_alvo;
         $largura_nova = round($largura_original * $altura_alvo / $altura_original);
         $nova = ImageCreateTrueColor($largura_nova, $altura_alvo);
         if ($fileType == 'image/png' || $fileType == 'image/gif') {
             imagealphablending($nova, false);
             imagesavealpha($nova, true);
             $transparent = imagecolorallocatealpha($nova, 255, 255, 255, 127);
             imagefilledrectangle($nova, 0, 0, $largura_nova, $altura_nova, $transparent);
         }
         imagecopyresampled($nova, $img, 0, 0, 0, 0, $largura_nova, $altura_nova, $largura_original, $altura_original);
     } else {
         $largura_nova = $largura_alvo;
         $nova = ImageCreateTrueColor($largura_alvo, $altura_nova);
         if ($fileType == 'image/png' || $fileType == 'image/gif') {
             imagealphablending($nova, false);
             imagesavealpha($nova, true);
             $transparent = imagecolorallocatealpha($nova, 255, 255, 255, 127);
             imagefilledrectangle($nova, 0, 0, $largura_alvo, $altura_nova, $transparent);
         }
         imagecopyresampled($nova, $img, 0, 0, 0, 0, $largura_alvo, $altura_nova, $largura_original, $altura_original);
     }
     if ($force) {
         $nova = ImageCreateTrueColor($maxW, $maxH);
         imagecopyresampled($nova, $img, 0, 0, 0, 0, $maxW, $maxH, $largura_original, $altura_original);
     }
     if ($fileType == 'image/jpeg' || $fileType == 'image/jpg' || $fileType == 'image/pjpeg') {
         if (!imagejpeg($nova, $imagemToResize, 100)) {
             $error = true;
         }
     } else {
         if ($fileType == 'image/png') {
             if (!imagepng($nova, $imagemToResize, 0)) {
                 $error = true;
             }
         } else {
             if ($fileType == 'image/gif') {
                 if (!imagegif($nova, $imagemToResize)) {
                     $error = true;
                 }
             }
         }
     }
     if ($error) {
         return 'Erro ao redimencionar ' . $toResize;
     } else {
         return true;
     }
 }
function resizeImage(&$image, $width, $height, $scale = false)
{
    $tmp_image = $image;
    $original_w = imagesX($image);
    $original_h = imagesY($image);
    $tmp_w = $tmp_h = 0;
    if ($scale === true) {
        $tmp_w = $width;
        $tmp_h = $width / $original_w * $original_h;
        if ($width / $original_w * $original_h > $height) {
            $tmp_h = $height;
            $tmp_w = $height / $original_h * $original_w;
        }
        $width = $tmp_w;
        $height = $tmp_h;
    }
    $image = imageCreateTrueColor($width, $height);
    imageCopyResized($image, $tmp_image, 0, 0, 0, 0, $width, $height, $original_w, $original_h);
    imageDestroy($tmp_image);
}
Exemple #8
0
}
if (isset($argv[2])) {
    $imagemnome = $argv[2];
} else {
    $imagemnome = "apple.jpg";
}
$formato = explode('.', $imagemnome);
$formato = $formato[count($formato) - 1];
if ($formato == 'jpg' or $formato == 'jpeg') {
    $imagem = imagecreatefromjpeg($imagemnome);
} elseif ($formato == 'png') {
    $imagem = imagecreatefrompng($imagemnome);
}
$nova = imagecreatetruecolor($terminalX, $terminalY);
$tamanhoX = imagesX($imagem);
$tamanhoY = imagesY($imagem);
imagecopyresampled($nova, $imagem, 0, 0, 0, 0, $terminalX, $terminalY, $tamanhoX, $tamanhoY);
for ($y = 0; $y <= $terminalY; $y++) {
    if ($argv[3] == '-s') {
        usleep(100000);
    }
    for ($x = 0; $x <= $terminalX; $x++) {
        $rgb = imagecolorat($nova, $x, $y);
        $rgb = imagecolorsforindex($nova, $rgb);
        $r = $rgb['red'] * 1.0;
        $g = $rgb['green'] * 1.0;
        $b = $rgb['blue'] * 1.0;
        if ($r + $g + $b < 100) {
            //Preto
            echo "A" . "";
        } elseif ($r + $g + $b > 650) {
 /**
  * image::rotate()
  * 
  * @param mixed $direction
  * @return
  */
 function rotate($direction)
 {
     if (empty($this->error)) {
         if ($this->is_destroy) {
             $this->get_createImage();
         }
         $direction = intval($direction);
         $direction = 360 - $direction % 360;
         if ($direction != 0 and $direction != 360) {
             $this->set_memory_limit();
             $workingImage = imagerotate($this->createImage, $direction, -1);
             imagealphablending($workingImage, true);
             imagesavealpha($workingImage, true);
             $this->createImage = $workingImage;
             $this->create_Image_info['width'] = imagesX($this->createImage);
             $this->create_Image_info['height'] = imagesY($this->createImage);
         }
     }
 }
Exemple #10
0
function addtagborder2($oim, $x, $y, $i, $startx, $starty, $outputsize, $shiftx, $shifty, $fuzzy)
{
    $width = imagesX($oim);
    $height = imagesY($oim);
    if ($fuzzy < 54 * 2) {
        $addx = 54 * 2 + 4;
    } else {
        $addx = 0;
    }
    if ($fuzzy < 22 * 2) {
        $addy = 22 * 2 + 4;
    } else {
        $addy = 0;
    }
    error_log(sprintf("addtagborder2: original: %d x %d => new size: %d x %d\n", $width, $height, $width + $addx, $height + $addy));
    $im = imagecreate($width + $addx, $height + $addy);
    $white = imageColorAllocate($im, 0xff, 0xff, 0xff);
    imageCopyMerge($im, $oim, 55, 23, 0, 0, imagesX($oim), imagesY($oim), 100);
    // 不需要算序號
    $tagx = $startx;
    $tagy = $starty;
    if ($i < $x) {
        // add top
        $topim = tagXline($tagx, $outputsize['x']);
        imageCopyMerge($im, $topim, 0, 0, 0, 0, imagesX($topim), imagesY($topim), 100);
        imagedestroy($topim);
    }
    if ($i >= $x * ($y - 1)) {
        // add buttom
        $topim = tagXline($tagx, $outputsize['x']);
        $ozy = $outputsize['y'];
        $tty = 22 + ($shifty % $ozy == 0 ? $ozy : $shifty % $ozy) * 315 + 2;
        // echo "tty = $tty $tileY % $ozy \n";
        imageCopyMerge($im, $topim, 0, $tty, 0, 0, imagesX($topim), imagesY($topim), 100);
        imagedestroy($topim);
    }
    if ($i % $x == 0) {
        // add left
        $topim = tagYline($tagy, $outputsize['y']);
        imageCopyMerge($im, $topim, 0, 0, 0, 0, imagesX($topim), imagesY($topim), 100);
        imagedestroy($topim);
    }
    if (($i + 1) % $x == 0) {
        // add right
        $topim = tagYline($tagy, $outputsize['y']);
        $ozx = $outputsize['x'];
        $ttx = 54 + ($shiftx % $ozx == 0 ? $ozx : $shiftx % $ozx) * 315 + 2;
        // echo "ttx = $ttx $tileX % $ozx \n";
        imageCopyMerge($im, $topim, $ttx, 0, 0, 0, imagesX($topim), imagesY($topim), 100);
        imagedestroy($topim);
    }
    return $im;
}
Exemple #11
0
function crearImagen($origen, $destino, $ancho = null, $alto = null, $background = false, $extension = ".jpg", $logo = "")
{
    $colors = array(255, 255, 255);
    list($w, $h, $type) = getimagesize($origen);
    if ($ancho == null) {
        $ancho = $w;
    }
    if ($alto == null) {
        $alto = $h;
    }
    if ($type == 1) {
        $src_img = @imagecreatefromgif($origen);
    } else {
        if ($type == 3) {
            $src_img = @imagecreatefrompng($origen);
        } else {
            if ($type == 6) {
                $src_img = @imagecreatefromwbmp($origen);
            }
        }
    }
    if (!empty($src_img)) {
        @imagegif($src_img, $origen);
    }
    ini_set('gd.jpeg_ignore_warning', 1);
    $old_x = imageSX($src_img);
    $old_y = imageSY($src_img);
    $thumb_w = $ancho;
    $thumb_h = $alto;
    $wRatio = $thumb_w / $old_x;
    $hRatio = $thumb_h / $old_y;
    if ($thumb_w > $old_x && $thumb_h > $old_y) {
        $ancho = $old_x;
        $altura = $old_y;
    } else {
        if ($wRatio * $old_y < $thumb_h) {
            $altura = ceil($wRatio * $old_y);
            $ancho = $thumb_w;
        } else {
            if ($hRatio * $old_x < $thumb_w) {
                $ancho = ceil($hRatio * $old_x);
                $altura = $thumb_h;
            } else {
                $ancho = $thumb_w;
                $altura = $thumb_h;
            }
        }
    }
    if (!$background) {
        $thumb_w = $ancho;
        $thumb_h = $altura;
    } else {
        $colors = hex2rgb($background);
    }
    $posx = $thumb_w / 2 - $ancho / 2;
    $posy = $thumb_h / 2 - $altura / 2;
    $dst_img = imagecreatetruecolor($thumb_w, $thumb_h);
    $colorfondo = imagecolorallocate($dst_img, $colors[0], $colors[1], $colors[2]);
    imagefilledrectangle($dst_img, 0, 0, $thumb_w, $thumb_h, $colorfondo);
    imagecopyresampled($dst_img, $src_img, $posx, $posy, 0, 0, $ancho, $altura, $old_x, $old_y);
    if ($logo != '') {
        $img_logo = imagecreatefrompng($logo);
        $logo_w = imagesX($img_logo);
        $logo_h = imagesY($img_logo);
        $pos_x = $ancho - $logo_w;
        imagecopyresampled($dst_img, $img_logo, $pos_x, 0, 0, 0, $pos_x, 0, $ancho, $altura);
        // imagecopy($dst_img, $img_logo, $ancho-$logo_w, $alto-$logo_h, 0, 0, $logo_w, $logo_h);
        imagecopy($dst_img, $img_logo, $pos_x, 0, 0, 0, $ancho, $logo_h);
    }
    switch ($extension) {
        case '.gif':
            imagegif($dst_img, $destino);
            break;
        case '.jpg':
        default:
            imagejpeg($dst_img, $destino, 90);
            break;
    }
    imagedestroy($dst_img);
    imagedestroy($src_img);
    $oldumask = umask(0);
    chmod($destino, 0777);
    umask($oldumask);
}
Exemple #12
0
 function y()
 {
     return imagesY($this->Img);
 }
 static function wytnij($zrodlowy, $docelowy, $newX, $newY)
 {
     if (!file_exists($zrodlowy)) {
         Strona::blad('Brak pliku: ' . $zrodlowy);
         return 1;
     }
     $return = 0;
     if ($img = @imagecreatefromjpeg($zrodlowy)) {
         $oldX = imagesX($img);
         $oldY = imagesY($img);
         if ($newX == 0) {
             $newX = $oldX;
         }
         if ($newY == 0) {
             $newY = $oldY;
         }
         $im = @imagecreatetruecolor($newX, $newY);
         if (!@imagecopy($im, $img, 0, 0, 0, 0, $newX, $newY)) {
             Strona::blad('Błąd imagecopyresized() ' . $zrodlowy);
         } else {
             @imagejpeg($im, $docelowy, 120);
             $return = 0;
         }
     } else {
         Strona::blad('Błąd imagecreatefromjpeg() ' . $zrodlowy);
     }
     return $return;
 }
Exemple #14
0
 /**
  * get image height
  */
 public function getHeight()
 {
     return imagesY($this->gd);
 }
function drawField($team)
{
    $field = imagecreatefromjpeg("img/field.jpg");
    foreach ($team->players as $player) {
        $img = drawPlayer($player->number, $player->name);
        $width = imagesx($img);
        $height = imagesy($img);
        $posX = $player->x - ($width - 26) / 2;
        $posY = $player->y - 10;
        imageAlphaBlending($field, true);
        // копировать сюда будем вместе с настройками
        imageSaveAlpha($field, true);
        // сохраняем
        imageCopy($field, $img, $posX, $posY, 0, 0, $width, $height);
        //копируем картинку с формой в пустой бокс
    }
    $copyright = drawCaption("http://www.ezheloko.ru/tactic", 12, 0);
    imagecopymerge_alpha($field, $copyright, 240, imagesY($field) - 25, 0, 0, imagesX($copyright), imagesY($copyright), 30);
    $name = generateName();
    $name = "formations/" . $name . ".png";
    imagePng($field, $name);
    return $name;
}
Exemple #16
0
 public static function hashImage($src)
 {
     if (!$src) {
         return false;
     }
     /*缩小圖片尺寸*/
     $delta = 8 * self::$rate;
     $img = imageCreateTrueColor($delta, $delta);
     imageCopyResized($img, $src, 0, 0, 0, 0, $delta, $delta, imagesX($src), imagesY($src));
     /*計算圖片灰階值*/
     $grayArray = array();
     for ($y = 0; $y < $delta; $y++) {
         for ($x = 0; $x < $delta; $x++) {
             $rgb = imagecolorat($img, $x, $y);
             $col = imagecolorsforindex($img, $rgb);
             $gray = intval(($col['red'] + $col['green'] + $col['blue']) / 3) & 0xff;
             $grayArray[] = $gray;
         }
     }
     imagedestroy($img);
     /*計算所有像素的灰階平均值*/
     $average = array_sum($grayArray) / count($grayArray);
     /*計算 hash 值*/
     $hashStr = '';
     foreach ($grayArray as $gray) {
         $hashStr .= $gray >= $average ? '1' : '0';
     }
     return $hashStr;
 }
Exemple #17
0
<?php
     if (!$params) {
         break;
     }
     $check_size_allowed($params);
     if (!preg_match('/^[0-9]+x[0-9]+x[0-9a-f]{6}$/i', $params)) {
         if (!Settings::isProductionState()) {
             exit('Error processing params for action "fill". Example: 32x32xff00cc');
         }
         die;
     }
     $check_size_allowed($params);
     list($x, $y, $c) = explode('x', $params);
     $image->apply();
     $ih = $image->getHandler();
     $c = imageColorAllocate($ih, hexdec($c[0] . $c[1]), hexdec($c[2] . $c[3]), hexdec($c[4] . $c[5]));
     imageFilledRectangle($ih, $x, $y, imagesX($ih), imagesY($ih), $c);
     unset($ih);
     break;
 case 'rectangle':
     if (!$params) {
         break;
     }
     $check_size_allowed($params);
     if (!preg_match('/^[0-9]+x[0-9]+x[0-9]+x[0-9]+x[0-9a-f]{6}$/i', $params)) {
         if (!Settings::isProductionState()) {
             exit('Error processing params for action "rectangle". Example: 32x32x64x64xff00cc');
         }
         die;
     }
     list($x1, $y1, $x2, $y2, $c) = explode('x', $params);
     $image->apply();
Exemple #19
0
function create_thumbnail_watermark($source, $destination, $new_width = 100, $new_height = 'auto', $quality = 100, $font_path, $font_size, $text_show)
{
    $im_src = imagecreatefromjpeg($source);
    if (!$im_src) {
        return;
    }
    $im_width = imagesX($im_src);
    $im_height = imagesY($im_src);
    if (!is_int($new_width) && is_int($new_height)) {
        // resize the image based on height
        $ratio = $im_height / $new_height;
        $new_width = floor($im_width / $ratio);
    } elseif (is_int($new_width) && !is_int($new_height)) {
        // resize the image based on the width
        $ratio = $im_width / $new_width;
        $new_height = floor($im_height / $ratio);
    }
    // create blank image
    $im = imagecreatetruecolor($new_width, $new_height);
    imagecopyresampled($im, $im_src, 0, 0, 0, 0, $new_width, $new_height, $im_width, $im_height);
    /****************************/
    $blue = imagecolorallocate($im, 253, 186, 16);
    // tentukan warna teks dalam RGB (255,255,255)
    $shadow = imagecolorallocate($im, 178, 178, 178);
    // efek teks shadow
    //	imagettftext($im, $font_size, 0, 31, 191, $shadow, $font_path, $text_show);  // posisikan logo watermark pada gambar
    imagettftext($im, $font_size, 0, 30, 190, $blue, $font_path, $text_show);
    /*********************************/
    imagejpeg($im, $destination, $quality);
    imagedestroy($im);
    imagedestroy($im_src);
}
Exemple #20
0
 /**
  * Get the height of this Image instance
  * @return int height
  */
 public function getHeight()
 {
     if (!isset($this->height)) {
         $this->height = imagesY($this->resource);
     }
     return $this->height;
 }
Exemple #21
0
    return $buatrewrite;
}
function get_link2($id, $kid, $title, $folder)
{
    $sharing = AuraCMSSEO($title);
    $buatrewrite = $folder . '-' . $id . '-' . $kid . '-' . $sharing . '.html';
    return $buatrewrite;
}
function get_link3($id, $title, $judul)
{
    $sharing = AuraCMSSEO($title);
    $buatrewrite = $judul . '-' . $id . '-' . $sharing . '.html';
    return $buatrewrite;
}
function get_link4($id, $kid, $judul)
{
    $buatrewrite = $judul . '-' . $id . '-' . $kid . '-' . $sharing . '.html';
    return $buatrewrite;
}
function create_thumbnail($source, $destination, $new_width = 100, $new_height = 'auto', $quality = 85)
{
    $im_src = imagecreatefromjpeg($source);
    if (!$im_src) {
        return;
 /**
  * public function tagImage
  * USED
  */
 public function tagImage($type, $position, $state, $file, $text, $font, $fontSize, $startX = null, $startY = null, $textColorRGB = 'variation')
 {
     $this->debug('function : ' . __FUNCTION__, 2, __LINE__);
     $addReflect = false;
     $site = $this->linker->site;
     $templateFolder = $site->templateFolder;
     // Gets the font and its params
     if (strpos($font, SH_FONTS_FOLDER) === false) {
         $font = str_replace(SH_FONTS_PATH, SH_FONTS_FOLDER, $font);
     }
     $fontParamsFile = substr($font, 0, -3) . 'php';
     if (!file_exists($font) || !file_exists($fontParamsFile)) {
         return false;
     }
     include $fontParamsFile;
     // Inserts a variable called $boxes
     foreach ($boxes as $textHeight => $box) {
         if ($box['fontSize'] == $fontSize) {
             break;
         }
     }
     if ($textColorRGB == 'variation') {
         $variation = $site->variation;
         if ($state == 'active') {
             $textColorRGB = str_replace('#', '', $this->linker->variation->get('buttonTextActive|buttonText', '999999'));
         } elseif ($state == 'selected') {
             $textColorRGB = str_replace('#', '', $this->linker->variation->get('buttonTextSelected|buttonText', '999999'));
         } else {
             $textColorRGB = str_replace('#', '', $this->linker->variation->get('buttonText', '999999'));
         }
     }
     // text color
     list($r, $g, $b) = str_split($textColorRGB, 2);
     $color['R'] = hexDec($r);
     $color['G'] = hexDec($g);
     $color['B'] = hexDec($b);
     // Gets the un-tagged image, and prepares it
     $srcImage = imagecreatefrompng($file);
     imagesavealpha($srcImage, true);
     $width = imagesX($srcImage);
     $height = imagesY($srcImage);
     $newImage = imageCreateTrueColor($width, $height);
     imagesavealpha($newImage, true);
     $textColor = imagecolorallocate($newImage, $color['R'], $color['G'], $color['B']);
     $transparentColor = imagecolorallocatealpha($newImage, 0, 0, 0, 127);
     imagefill($newImage, 0, 0, $transparentColor);
     imagecopy($newImage, $srcImage, 0, 0, 0, 0, $width, $height);
     // Free the space
     imagedestroy($srcImage);
     imagecolortransparent($newImage, $transparentColor);
     if ($startX == null || strtoupper($startX) == 'NULL') {
         if (file_exists($this->builderFolder . $type . '/model/' . $position . '.php')) {
             include $this->builderFolder . $type . '/model/' . $position . '.php';
             $textBox = imagettfbbox($fontSize, 0, $font, $text);
             $startX = $image['startLeft'] + $box['left'];
             $startY = $image['startTop'] + $box['top'];
         }
     }
     /*
            if($addReflect == true){
                $reflect = imagecreatetruecolor($width,$textHeight / 2);
                $textColor2 = imagecolorallocate(
                    $reflect,
                    $color['R'],
                    $color['G'],
                    $color['B']
                );
                $transparentColor2 = imagecolorallocatealpha(
                    $reflect,
                    $transparentColorRGB['R'],
                    $transparentColorRGB['G'],
                    $transparentColorRGB['B'],
                    127
                );
                imagefill($reflect,0,0,$transparentColor2);
                imagecolortransparent($reflect, $transparentColor2);
     
                // writes the text
                imagettftext(
                    $reflect,
                    $fontSize,
                    0,
                    $startX,
                    $image['startTop'],
                    $textColor2,
                    $font,
                    $text
                );
                $cpt = 0;
                $open = false;
                // Gets the pixels that are colored in the first line
                for($a = 1; $a<$width + 1;$a++){
                    for($b = 1; $b<($textHeight / 2) - 1;$b++){
                        $color = imagecolorat($reflect, $a, $b);
                        $colorrgb = imagecolorsforindex($reflect,$color);
     
                        if($colorrgb['alpha'] < 67){
                            $trans = $colorrgb['alpha'] + 127 - ($b / ($textHeight / 2)) * 67;
                            if($trans<127){
                                $tempColor = imagecolorallocatealpha($newImage,
                                    $colorrgb['red'],
                                    $colorrgb['green'],
                                    $colorrgb['blue'],
                                    $trans
                                );
                                imagesetpixel(
                                    $newImage,
                                    $a,
                                    $startY + ($textHeight / 2) - $b,
                                    $tempColor
                                );
                            }
                        }
                    }
                }
                imageDestroy($reflect);
            }
     *
     */
     // writes the text
     imagettftext($newImage, $fontSize, 0, $startX, $startY, $textColor, $font, $text);
     imagepng($newImage, $file);
     imageDestroy($newImage);
     return true;
 }