/**
  * Based on the Watermark function by Marek Malcherek  
  * http://www.malcherek.de
  *
  * @param string $color
  * @param string $wmFont
  * @param int $wmSize
  * @param int $wmOpaque
  */
 function watermarkCreateText($color = '000000', $wmFont, $wmSize = 10, $wmOpaque = 90)
 {
     // set font path
     $wmFontPath = NGGALLERY_ABSPATH . "fonts/" . $wmFont;
     if (!is_readable($wmFontPath)) {
         return;
     }
     // This function requires both the GD library and the FreeType library.
     if (!function_exists('ImageTTFBBox')) {
         return;
     }
     $words = preg_split('/ /', $this->watermarkText);
     $lines = array();
     $line = '';
     $watermark_image_width = 0;
     // attempt adding a new word until the width is too large; then start a new line and start again
     foreach ($words as $word) {
         // sanitize the text being input; imagettftext() can be sensitive
         $TextSize = $this->ImageTTFBBoxDimensions($wmSize, 0, $wmFontPath, $line . preg_replace('~^(&([a-zA-Z0-9]);)~', htmlentities('${1}'), mb_convert_encoding($word, "HTML-ENTITIES", "UTF-8")));
         if ($watermark_image_width == 0) {
             $watermark_image_width = $TextSize['width'];
         }
         if ($TextSize['width'] > $this->newDimensions['newWidth']) {
             $lines[] = trim($line);
             $line = '';
         } else {
             if ($TextSize['width'] > $watermark_image_width) {
                 $watermark_image_width = $TextSize['width'];
             }
         }
         $line .= $word . ' ';
     }
     $lines[] = trim($line);
     // use this string to determine our largest possible line height
     $line_dimensions = $this->ImageTTFBBoxDimensions($wmSize, 0, $wmFontPath, 'MXQJALYmxqjabdfghjklpqry019`@$^&*(,!132');
     $line_height = $line_dimensions['height'] * 1.05;
     // Create an image to apply our text to
     $this->workingImage = ImageCreateTrueColor($watermark_image_width, count($lines) * $line_height);
     ImageSaveAlpha($this->workingImage, true);
     ImageAlphaBlending($this->workingImage, false);
     $bgText = imagecolorallocatealpha($this->workingImage, 255, 255, 255, 127);
     imagefill($this->workingImage, 0, 0, $bgText);
     $wmTransp = 127 - $wmOpaque * 1.27;
     $rgb = $this->hex2rgb($color, false);
     $TextColor = imagecolorallocatealpha($this->workingImage, $rgb[0], $rgb[1], $rgb[2], $wmTransp);
     // Put text on the image, line-by-line
     $y_pos = $wmSize;
     foreach ($lines as $line) {
         imagettftext($this->workingImage, $wmSize, 0, 0, $y_pos, $TextColor, $wmFontPath, $line);
         $y_pos += $line_height;
     }
     $this->watermarkImgPath = $this->workingImage;
     return;
 }
Exemplo n.º 2
0
 /**
  * Agrega una marca de agua a la foto
  * @param string $absolutePath
  */
 private function _addWaterMark($absolutePath)
 {
     $DOC_ROOT = $this->_CI->input->server('DOCUMENT_ROOT') . "/";
     if (FALSE === is_file($absolutePath)) {
         return FALSE;
     }
     switch (TRUE) {
         case stristr($absolutePath, 'jpg'):
             $photoImage = ImageCreateFromJpeg("{$absolutePath}");
             break;
         case stristr($absolutePath, 'gif'):
             $photoImage = ImageCreateFromGIF("{$absolutePath}");
             break;
         case stristr($absolutePath, 'png'):
             $photoImage = ImageCreateFromPNG("{$absolutePath}");
             break;
     }
     ImageAlphaBlending($photoImage, true);
     // Añadimos aquí el fichero de marca de agua.
     $logoImage = ImageCreateFromPNG($DOC_ROOT . "assets/imagenes/marca_agua_telam.png");
     $logoW = ImageSX($logoImage);
     $logoH = ImageSY($logoImage);
     $tamanox = imagesx($photoImage);
     $ubicacionX = ($tamanox - $logoW) / 2;
     $tamanoy = imagesy($photoImage);
     $ubicacionY = ($tamanoy - $logoH) / 2;
     ImageCopy($photoImage, $logoImage, $ubicacionX, $ubicacionY, 0, 0, $logoW, $logoH);
     imagejpeg($photoImage, $absolutePath);
     ImageDestroy($photoImage);
     ImageDestroy($logoImage);
 }
Exemplo n.º 3
0
function marcadeagua($img_original, $img_marcadeagua, $img_nueva, $calidad)
{
    // obtener datos de la fotografia
    $info_original = getimagesize($img_original);
    $anchura_original = $info_original[0];
    $altura_original = $info_original[1];
    // obtener datos de la "marca de agua"
    $info_marcadeagua = getimagesize($img_marcadeagua);
    $anchura_marcadeagua = $info_marcadeagua[0];
    $altura_marcadeagua = $info_marcadeagua[1];
    // calcular la posición donde debe copiarse la "marca de agua" en la fotografia
    /* 
    // Posicion: Centrado
    $horizmargen = ($anchura_original - $anchura_marcadeagua)/2; 
    $vertmargen = ($altura_original - $altura_marcadeagua)/2; 
    */
    // Posicion: abajo a la izquierda
    $horizmargen = 10;
    $vertmargen = $altura_original - $altura_marcadeagua - 10;
    // crear imagen desde el original
    $original = ImageCreateFromJPEG($img_original);
    ImageAlphaBlending($original, true);
    // crear nueva imagen desde la marca de agua
    $marcadeagua = ImageCreateFromPNG($img_marcadeagua);
    // copiar la "marca de agua" en la fotografia
    ImageCopy($original, $marcadeagua, $horizmargen, $vertmargen, 0, 0, $anchura_marcadeagua, $altura_marcadeagua);
    // guardar la nueva imagen
    ImageJPEG($original, $img_nueva, $calidad);
    // cerrar las imágenes
    ImageDestroy($original);
    ImageDestroy($marcadeagua);
}
Exemplo n.º 4
0
 function watermark($pngImage, $left = 0, $top = 0)
 {
     ImageAlphaBlending($this->image, true);
     $layer = ImageCreateFromPNG($pngImage);
     $logoW = ImageSX($layer);
     $logoH = ImageSY($layer);
     ImageCopy($this->image, $layer, $left, $top, 0, 0, $logoW, $logoH);
 }
Exemplo n.º 5
0
	function canvas ($width,$height,$alpha=false) {
		$this->processed = ImageCreateTrueColor($width,$height);
		if ($alpha) {
			ImageAlphaBlending($this->processed, false);
			$transparent = ImageColorAllocateAlpha($this->processed, 0, 0, 0, 127);
			ImageFill($this->processed, 0, 0, $transparent);
			ImageSaveAlpha($this->processed, true);
			$this->alpha = true;
		}
	}
 public function copy_image($url, $logo)
 {
     $bwidth = imagesx($url);
     $bheight = imagesy($url);
     $lwidth = imagesx($logo);
     $lheight = imagesy($logo);
     $src_x = $bwidth - ($lwidth + 5);
     $src_y = $bheight - ($lheight + 5);
     ImageAlphaBlending($url, true);
     ImageCopy($url, $logo, $src_x, $src_y, 0, 0, $lwidth, $lheight);
 }
Exemplo n.º 7
0
 function imageConvolution($src, $filter, $filter_div, $offset)
 {
     if ($src == NULL) {
         return 0;
     }
     $sx = imagesx($src);
     $sy = imagesy($src);
     $srcback = ImageCreateTrueColor($sx, $sy);
     ImageAlphaBlending($srcback, false);
     ImageAlphaBlending($src, false);
     ImageCopy($srcback, $src, 0, 0, 0, 0, $sx, $sy);
     if ($srcback == NULL) {
         return 0;
     }
     for ($y = 0; $y < $sy; ++$y) {
         for ($x = 0; $x < $sx; ++$x) {
             $new_r = $new_g = $new_b = 0;
             $alpha = imagecolorat($srcback, @$pxl[0], @$pxl[1]);
             $new_a = $alpha >> 24;
             for ($j = 0; $j < 3; ++$j) {
                 $yv = min(max($y - 1 + $j, 0), $sy - 1);
                 for ($i = 0; $i < 3; ++$i) {
                     $pxl = array(min(max($x - 1 + $i, 0), $sx - 1), $yv);
                     $rgb = imagecolorat($srcback, $pxl[0], $pxl[1]);
                     $new_r += ($rgb >> 16 & 0xff) * $filter[$j][$i];
                     $new_g += ($rgb >> 8 & 0xff) * $filter[$j][$i];
                     $new_b += ($rgb & 0xff) * $filter[$j][$i];
                     $new_a += ((0x7f000000 & $rgb) >> 24) * $filter[$j][$i];
                 }
             }
             $new_r = $new_r / $filter_div + $offset;
             $new_g = $new_g / $filter_div + $offset;
             $new_b = $new_b / $filter_div + $offset;
             $new_a = $new_a / $filter_div + $offset;
             $new_r = $new_r > 255 ? 255 : ($new_r < 0 ? 0 : $new_r);
             $new_g = $new_g > 255 ? 255 : ($new_g < 0 ? 0 : $new_g);
             $new_b = $new_b > 255 ? 255 : ($new_b < 0 ? 0 : $new_b);
             $new_a = $new_a > 127 ? 127 : ($new_a < 0 ? 0 : $new_a);
             $new_pxl = ImageColorAllocateAlpha($src, (int) $new_r, (int) $new_g, (int) $new_b, $new_a);
             if ($new_pxl == -1) {
                 $new_pxl = ImageColorClosestAlpha($src, (int) $new_r, (int) $new_g, (int) $new_b, $new_a);
             }
             if ($y >= 0 && $y < $sy) {
                 imagesetpixel($src, $x, $y, $new_pxl);
             }
         }
     }
     imagedestroy($srcback);
     return 1;
 }
 /**
 	// watermark
 	// source : php.net
 */
 function watermark($name, $ext)
 {
     ($hook = kleeja_run_hook('watermark_func_kljuploader')) ? eval($hook) : null;
     //run hook
     if (!file_exists($name)) {
         return;
     }
     if (strpos($ext, 'jp') !== false) {
         $src_img = @imagecreatefromjpeg($name);
     } elseif (strpos($ext, 'png') !== false) {
         $src_img = @imagecreatefrompng($name);
     } elseif (strpos($ext, 'gif') !== false) {
         $src_img = @imagecreatefromgif($name);
     } else {
         return;
     }
     if (file_exists('images/watermark.gif')) {
         $src_logo = imagecreatefromgif('images/watermark.gif');
     } elseif (file_exists('images/watermark.png')) {
         $src_logo = imagecreatefrompng('images/watermark.png');
     }
     $bwidth = @imageSX($src_img);
     $bheight = @imageSY($src_img);
     $lwidth = @imageSX($src_logo);
     $lheight = @imageSY($src_logo);
     //fix bug for 1beta3
     if ($bwidth > 160 && $bheight > 130) {
         $src_x = $bwidth - ($lwidth + 5);
         $src_y = $bheight - ($lheight + 5);
         @ImageAlphaBlending($src_img, true);
         @ImageCopy($src_img, $src_logo, $src_x, $src_y, 0, 0, $lwidth, $lheight);
         if (strpos($ext, 'jp') !== false) {
             @imagejpeg($src_img, $name);
         } elseif (strpos($ext, 'png') !== false) {
             @imagepng($src_img, $name);
         } elseif (strpos($ext, 'gif') !== false) {
             @imagegif($src_img, $name);
         }
     } else {
         return false;
     }
 }
Exemplo n.º 9
0
function cs_resample($image, $target, $max_width, $max_height)
{
    $gd_info = gd_info();
    $im_info = array();
    if (file_exists($image)) {
        $im_info = getimagesize($image);
    } else {
        cs_error(__FILE__, 'Image file does not exist: "' . $image . '"');
        return false;
    }
    if ($im_info[2] == 1 and !empty($gd_info["GIF Read Support"])) {
        $src = ImageCreateFromGIF($image);
    } elseif ($im_info[2] == 2 and (!empty($gd_info["JPG Support"]) or !empty($gd_info["JPEG Support"]))) {
        $src = ImageCreateFromJPEG($image);
    } elseif ($im_info[2] == 3 and !empty($gd_info["PNG Support"])) {
        $src = ImageCreateFromPNG($image);
    } else {
        cs_error(__FILE__, 'Image filetype is not supported: "' . $image . '"');
        return false;
    }
    $factor = max($im_info[1] / $max_height, $im_info[0] / $max_width);
    $im_new[0] = floor($im_info[0] / $factor);
    $im_new[1] = floor($im_info[1] / $factor);
    $dst = ImageCreateTrueColor($im_new[0], $im_new[1]);
    ImageAlphaBlending($dst, false);
    ImageSaveAlpha($dst, true);
    ImageCopyResampled($dst, $src, 0, 0, 0, 0, $im_new[0], $im_new[1], $im_info[0], $im_info[1]);
    if ($im_info[2] == 1) {
        $return = ImageGIF($dst, $target) ? 1 : 0;
    } elseif ($im_info[2] == 2) {
        $return = ImageJPEG($dst, $target, 100) ? 1 : 0;
    } elseif ($im_info[2] == 3) {
        $return = ImagePNG($dst, $target) ? 1 : 0;
    } else {
        cs_error(__FILE__, 'Failed to write resampled image file: "' . $target . '"');
        return false;
    }
    return $return;
}
Exemplo n.º 10
0
 /**
  * Based on the Watermark function by Marek Malcherek
  * http://www.malcherek.de
  *
  * @param string $color
  * @param string $wmFont
  * @param int $wmSize
  * @param int $wmOpaque
  */
 function watermarkCreateText($color = '000000', $wmFont, $wmSize = 10, $wmOpaque = 90)
 {
     // set font path
     $wmFontPath = NGGALLERY_ABSPATH . "fonts/" . $wmFont;
     if (!is_readable($wmFontPath)) {
         return;
     }
     // This function requires both the GD library and the FreeType library.
     if (!function_exists('ImageTTFBBox')) {
         return;
     }
     $TextSize = @ImageTTFBBox($wmSize, 0, $wmFontPath, $this->watermarkText) or die;
     $TextWidth = abs($TextSize[2]) + abs($TextSize[0]);
     $TextHeight = abs($TextSize[7]) + abs($TextSize[1]);
     // Create Image for Text
     $this->workingImage = ImageCreateTrueColor($TextWidth, $TextHeight);
     ImageSaveAlpha($this->workingImage, true);
     ImageAlphaBlending($this->workingImage, false);
     $bgText = imagecolorallocatealpha($this->workingImage, 255, 255, 255, 127);
     imagefill($this->workingImage, 0, 0, $bgText);
     $wmTransp = 127 - $wmOpaque * 1.27;
     $rgb = $this->hex2rgb($color, false);
     $TextColor = imagecolorallocatealpha($this->workingImage, $rgb[0], $rgb[1], $rgb[2], $wmTransp);
     // Create Text on image
     imagettftext($this->workingImage, $wmSize, 0, 0, abs($TextSize[5]), $TextColor, $wmFontPath, $this->watermarkText);
     $this->watermarkImgPath = $this->workingImage;
     return;
 }
function oos_watermark($pic, $image_new, $quality = '100')
{
    $dst_img = '';
    $imageInfo = GetImageSize($pic);
    $width = $imageInfo[0];
    $height = $imageInfo[1];
    $logoinfo = getimagesize(OOS_WATERMARK_LOGO);
    $logowidth = $logoinfo[0];
    $logoheight = $logoinfo[1];
    if (function_exists('imagecreatefromjpeg')) {
        // check if php with gd-lib-support is installed
        if ($imageInfo[2] == 1) {
            if (function_exists('imagecreatefromgif')) {
                $src_img = imagecreatefromgif($pic);
            }
        }
        if ($imageInfo[2] == 2) {
            if (function_exists('imagecreatefromjpeg')) {
                $src_img = imagecreatefromjpeg($pic);
            }
        }
        if ($imageInfo[2] == 3) {
            if (function_exists('imagecreatefrompng')) {
                $src_img = imagecreatefrompng($pic);
            }
        }
        if ($src_img) {
            if (OOS_BIGIMAGE_WIDTH || OOS_BIGIMAGE_HEIGHT) {
                // proportionaler resize; width oder height ist die maximale Größe
                $x = OOS_BIGIMAGE_WIDTH / $width;
                $y = OOS_BIGIMAGE_HEIGHT / $height;
                if ($y > 0 && $y < $x || $x == 0) {
                    $x = $y;
                }
                $width_big = $width * $x;
                $height_big = $height * $x;
                $width = $width_big;
                $height = $height_big;
                if (OOS_GD_LIB_VERSION == '2') {
                    $dst_img = imagecreatetruecolor($width_big, $height_big);
                    imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $width_big, $height_big, imagesx($src_img), imagesy($src_img));
                } else {
                    $dst_img = imagecreate($width_big, $height_big);
                    imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $width_big, $height_big, imagesx($src_img), imagesy($src_img));
                }
            } else {
                $dst_img = $src_img;
            }
            $hori = $width - $logowidth;
            $vert = $height - $logoheight;
            $horizmargin = round($hori / 2);
            $vertmargin = round($vert / 2);
            ImageAlphaBlending($dst_img, true);
            $logoImage = ImageCreateFromPNG(OOS_WATERMARK_LOGO);
            $logoW = ImageSX($logoImage);
            $logoH = ImageSY($logoImage);
            ImageCopy($dst_img, $logoImage, $horizmargin, $vertmargin, 0, 0, $logoW, $logoH);
            // Copy Picture
            $fh = fopen($image_new, 'w');
            fclose($fh);
            if ($imageInfo[2] == 1) {
                imagegif($dst_img, $image_new);
            }
            if ($imageInfo[2] == 2) {
                imagejpeg($dst_img, $image_new, $quality);
            }
            if ($imageInfo[2] == 3) {
                imagepng($dst_img, $image_new);
            }
            return true;
        }
    }
    // pic couldn't be resized, so copy original
    copy($pic, $image_new);
    return false;
}
Exemplo n.º 12
0
 function replaceTransparentWhite($im)
 {
     $src_w = ImageSX($im);
     $src_h = ImageSY($im);
     $backgroundimage = imagecreatetruecolor($src_w, $src_h);
     $white = ImageColorAllocate($backgroundimage, 255, 255, 255);
     ImageFill($backgroundimage, 0, 0, $white);
     ImageAlphaBlending($backgroundimage, TRUE);
     imagecopy($backgroundimage, $im, 0, 0, 0, 0, $src_w, $src_h);
     return $backgroundimage;
 }
Exemplo n.º 13
0
    // great
} elseif (@$_GET['new']) {
    // generate a blank image resource of the specified size/background color/opacity
    if ($phpThumb->w <= 0 || $phpThumb->h <= 0) {
        $phpThumb->ErrorImage('"w" and "h" parameters required for "new"');
    }
    @(list($bghexcolor, $opacity) = explode('|', $_GET['new']));
    if (!phpthumb_functions::IsHexColor($bghexcolor)) {
        $phpThumb->ErrorImage('BGcolor parameter for "new" is not valid');
    }
    $opacity = strlen($opacity) ? $opacity : 100;
    if ($phpThumb->gdimg_source = phpthumb_functions::ImageCreateFunction($phpThumb->w, $phpThumb->h)) {
        $alpha = (100 - min(100, max(0, $opacity))) * 1.27;
        if ($alpha) {
            $phpThumb->setParameter('is_alpha', true);
            ImageAlphaBlending($phpThumb->gdimg_source, false);
            ImageSaveAlpha($phpThumb->gdimg_source, true);
        }
        $new_background_color = phpthumb_functions::ImageHexColorAllocate($phpThumb->gdimg_source, $bghexcolor, false, $alpha);
        ImageFilledRectangle($phpThumb->gdimg_source, 0, 0, $phpThumb->w, $phpThumb->h, $new_background_color);
    } else {
        $phpThumb->ErrorImage('failed to create "new" image (' . $phpThumb->w . 'x' . $phpThumb->h . ')');
    }
} elseif (!$phpThumb->src) {
    $phpThumb->ErrorImage('Usage: ' . $_SERVER['PHP_SELF'] . '?src=/path/and/filename.jpg' . "\n" . 'read Usage comments for details');
} elseif (preg_match('/^(f|ht)tp\\:\\/\\//i', $phpThumb->src)) {
    $phpThumb->DebugMessage('$phpThumb->src (' . $phpThumb->src . ') is remote image, attempting to download', __FILE__, __LINE__);
    if ($phpThumb->config_http_user_agent) {
        $phpThumb->DebugMessage('Setting "user_agent" to "' . $phpThumb->config_http_user_agent . '"', __FILE__, __LINE__);
        ini_set('user_agent', $phpThumb->config_http_user_agent);
    }
 private function SaveQValueAssociationImage()
 {
     if (!array_key_exists('associationimage', $_FILES) || $_FILES['associationimage']['error'] !== 0 || strtolower(substr($_FILES['associationimage']['type'], 0, 6)) !== 'image/') {
         return false;
     }
     // Attempt to set the memory limit
     setImageFileMemLimit($_FILES['associationimage']['tmp_name']);
     // Generate the destination path
     $randomDir = strtolower(chr(rand(65, 90)));
     $destPath = realpath(ISC_BASE_PATH . '/' . GetConfig('ImageDirectory'));
     if (!is_dir($destPath . '/' . $randomDir)) {
         if (!@mkdir($destPath . '/' . $randomDir, 0777)) {
             $randomDir = '';
         }
     }
     $destFile = GenRandFileName($_FILES['associationimage']['name'], 'category');
     $destPath = $destPath . '/' . $randomDir . '/' . $destFile;
     $returnPath = $randomDir . '/' . $destFile;
     $tmp = explode('.', $_FILES['associationimage']['name']);
     $ext = strtolower($tmp[count($tmp) - 1]);
     if ($ext == 'jpg') {
         $srcImg = imagecreatefromjpeg($_FILES['associationimage']['tmp_name']);
     } else {
         if ($ext == 'gif') {
             $srcImg = imagecreatefromgif($_FILES['associationimage']['tmp_name']);
             if (!function_exists('imagegif')) {
                 $gifHack = 1;
             }
         } else {
             $srcImg = imagecreatefrompng($_FILES['associationimage']['tmp_name']);
         }
     }
     $srcWidth = imagesx($srcImg);
     $srcHeight = imagesy($srcImg);
     $widthLimit = GetConfig('BrandImageWidth');
     $heightLimit = GetConfig('BrandImageHeight');
     // If the image is small enough, simply move it and leave it as is
     if ($srcWidth <= $widthLimit && $srcHeight <= $heightLimit) {
         imagedestroy($srcImg);
         move_uploaded_file($_FILES['associationimage']['tmp_name'], $destPath);
         return $returnPath;
     }
     // Otherwise, the image needs to be resized
     $attribs = getimagesize($_FILES['associationimage']['tmp_name']);
     $width = $attribs[0];
     $height = $attribs[1];
     if ($width > $widthLimit) {
         $height = ceil($widthLimit / $width * $height);
         $width = $widthLimit;
     }
     if ($height > $heightLimit) {
         $width = ceil($heightLimit / $height * $width);
         $height = $heightLimit;
     }
     $dstImg = imagecreatetruecolor($width, $height);
     if ($ext == "gif" && !isset($gifHack)) {
         $colorTransparent = imagecolortransparent($srcImg);
         imagepalettecopy($srcImg, $dstImg);
         imagecolortransparent($dstImg, $colorTransparent);
         imagetruecolortopalette($dstImg, true, 256);
     } else {
         if ($ext == "png") {
             ImageColorTransparent($dstImg, ImageColorAllocate($dstImg, 0, 0, 0));
             ImageAlphaBlending($dstImg, false);
         }
     }
     imagecopyresampled($dstImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);
     if ($ext == "jpg") {
         imagejpeg($dstImg, $destPath, 100);
     } else {
         if ($ext == "gif") {
             if (isset($gifHack) && $gifHack == true) {
                 $thumbFile = isc_substr($destPath, 0, -3) . "jpg";
                 imagejpeg($dstImg, $destPath, 100);
             } else {
                 imagegif($dstImg, $destPath);
             }
         } else {
             imagepng($dstImg, $destPath);
         }
     }
     @imagedestroy($dstImg);
     @imagedestroy($srcImg);
     @unlink($_FILES['associationimage']['tmp_name']);
     // Change the permissions on the thumbnail file
     isc_chmod($returnPath, ISC_WRITEABLE_FILE_PERM);
     return $returnPath;
 }
Exemplo n.º 15
0
<?php

// Rectangle Version
$filename = __DIR__ . '/php.png';
// Thumbnail Dimentions
$w = 50;
$h = 20;
// Images
$original = ImageCreateFromPNG($filename);
$thumbnail = ImageCreateTrueColor($w, $h);
// Preserve Transparency
ImageColorTransparent($thumbnail, ImageColorAllocateAlpha($thumbnail, 0, 0, 0, 127));
ImageAlphaBlending($thumbnail, false);
ImageSaveAlpha($thumbnail, true);
// Scale & Copy
$x = ImageSX($original);
$y = ImageSY($original);
$scale = min($x / $w, $y / $h);
ImageCopyResampled($thumbnail, $original, 0, 0, ($x - $w * $scale) / 2, ($y - $h * $scale) / 2, $w, $h, $w * $scale, $h * $scale);
// Send
header('Content-type: image/png');
ImagePNG($thumbnail);
ImageDestroy($original);
ImageDestroy($thumbnail);
Exemplo n.º 16
0
 function _imageCreate($aWidth, $aHeight)
 {
     if ($aWidth <= 1 || $aHeight <= 1) {
         JpGraphError::RaiseL(12006, $aWidth, $aHeight);
         //("Illegal sizes specified for width or height when creating an image, (width=$aWidth, height=$aHeight)");
     }
     $this->img = @imagecreatetruecolor($aWidth, $aHeight);
     if ($this->img < 1) {
         JpGraphError::RaiseL(12011);
         // die("<b>JpGraph Error:</b> Can't create truecolor image. Check that you really have GD2 library installed.");
     }
     ImageAlphaBlending($this->img, true);
 }
Exemplo n.º 17
0
 * the GNU Lesser General Public License along with this library; if not, write
 * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 * 02111-1307 USA
 *
 * @category   Images
 * @package    Image_Graph
 * @subpackage Tests
 * @author     Jesper Veggerby <*****@*****.**>
 * @copyright  Copyright (C) 2003, 2004 Jesper Veggerby Hansen
 * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
 * @version    CVS: $Id$
 * @link       http://pear.php.net/package/Image_Graph
 */
// create a true color image (requires GD2)
$image = ImageCreateTrueColor(400, 300);
ImageAlphaBlending($image, true);
// allocate some colors
$black = ImageColorAllocate($image, 0, 0, 0);
$red = ImageColorAllocate($image, 0xff, 0, 0);
$green = ImageColorAllocate($image, 0, 0xff, 0);
$blue = ImageColorAllocate($image, 0, 0, 0xff);
$white = ImageColorAllocate($image, 0xff, 0xff, 0xff);
// create a frame
ImageFilledRectangle($image, 0, 0, 399, 299, $white);
ImageRectangle($image, 0, 0, 399, 299, $black);
// draw some lines
ImageLine($image, 200, 50, 350, 150, $red);
ImageLine($image, 200, 60, 350, 160, $green);
ImageLine($image, 200, 70, 350, 170, $blue);
// draw some overlapping alpha blended boxes
$redAlpha = ImageColorAllocateAlpha($image, 0xff, 0, 0, 75);
Exemplo n.º 18
0
 public static function beResizeImg($isrc, $idst, $iw, $ih, $ip = 'keep', $imax = 'yes', $iqual = 95)
 {
     /* parameters
        $isrc					source file
        $idst					destination folder
        $iw						new width
        $ih						new height
        $ip='keep'		keep proportions
        $imax='yes'		treat width/height as maximums
        $iqual=95			image quality
        */
     //read array with source image information
     $imagedata = getimagesize($isrc);
     //calculate new width and height
     $srcwid = $imagedata[0];
     $srchei = $imagedata[1];
     $srcx = $srcy = 0;
     //if no height is set we calculate it
     if ($ih == "full") {
         $ih = (int) ($imagedata[1] * ($iw / $imagedata[0]));
     }
     //the new width
     $new_iw = (int) $iw;
     //the new height
     if ($ip == 'keep') {
         //keep proportions
         $new_ih = (int) ($imagedata[1] * ($new_iw / $imagedata[0]));
         if ($new_ih > $ih) {
             $new_ih = (int) $ih;
             $new_iw = (int) ($imagedata[0] * ($new_ih / $imagedata[1]));
         }
     } else {
         //set fixed height
         $new_ih = (int) $ih;
         //crop
         if ($imagedata[0] / $new_iw < $imagedata[1] / $new_ih) {
             //original to heigh
             $srchei = (int) ($new_ih * ($imagedata[0] / $new_iw));
             $srcy = (int) (($imagedata[1] - $srchei) / 2);
         } elseif ($imagedata[0] / $new_iw > $imagedata[1] / $new_ih) {
             //original to wide
             $srcwid = (int) ($new_iw * ($imagedata[1] / $new_ih));
             $srcx = (int) (($imagedata[0] - $srcwid) / 2);
         }
     }
     //set image type and set image name
     $ipath = pathinfo($isrc);
     $itype = strtolower($ipath["extension"]);
     $iname = substr($ipath["basename"], 0, -(strlen($itype) + 1)) . "_" . $new_iw . "_" . $new_ih . "_" . $iqual . "." . $itype;
     //check if $idst is set to a subdirectory and if so add it to the path
     $idir = $idst != "" ? $ipath["dirname"] . "/" . $idst : $ipath["dirname"];
     //check if image exists, else create it
     if (!JFile::exists($idir . "/" . $iname)) {
         if ($itype == "jpg" && function_exists("imagecreatefromjpeg")) {
             $image = imagecreatefromjpeg($isrc);
             $image_dest = imagecreatetruecolor($new_iw, $new_ih);
             imagecopyresampled($image_dest, $image, 0, 0, $srcx, $srcy, $new_iw, $new_ih, $srcwid, $srchei);
             ob_start();
             // start a new output buffer
             imagejpeg($image_dest, NULL, $iqual);
             $buffer = ob_get_contents();
             ob_end_clean();
             // stop this output buffer
         } elseif ($itype == "gif" && function_exists("imagecreatefromgif")) {
             $image = imagecreatefromgif($isrc);
             $image_dest = imagecreatetruecolor($new_iw, $new_ih);
             imagealphablending($image_dest, false);
             // get and reallocate transparency-color
             $transindex = imagecolortransparent($image);
             if ($transindex >= 0) {
                 $transcol = imagecolorsforindex($image, $transindex);
                 $transindex = imagecolorallocatealpha($image_dest, $transcol['red'], $transcol['green'], $transcol['blue'], 127);
                 imagefill($image_dest, 0, 0, $transindex);
             }
             // resample
             imagecopyresampled($image_dest, $image, 0, 0, $srcx, $srcy, $new_iw, $new_ih, $srcwid, $srchei);
             // restore transparency
             if ($transindex >= 0) {
                 imagecolortransparent($image_dest, $transindex);
                 for ($y = 0; $y < $new_ih; ++$y) {
                     for ($x = 0; $x < $new_iw; ++$x) {
                         if ((imagecolorat($image_dest, $x, $y) >> 24 & 0x7f) >= 100) {
                             imagesetpixel($image_dest, $x, $y, $transindex);
                         }
                     }
                 }
             }
             imagetruecolortopalette($image_dest, true, 255);
             imagesavealpha($image_dest, false);
             ob_start();
             // start a new output buffer
             imagegif($image_dest, NULL, $iqual);
             $buffer = ob_get_contents();
             ob_end_clean();
             // stop this output buffer
         } elseif ($itype == "png" && function_exists("imagecreatefrompng")) {
             $image = ImageCreateFromPng($isrc);
             $image_dest = ImageCreateTrueColor($new_iw, $new_ih);
             $transindex = imagecolortransparent($image);
             $istruecolor = imageistruecolor($image);
             if ($transindex >= 0) {
                 ImageColorTransparent($image_dest, ImageColorAllocate($image_dest, 0, 0, 0));
                 ImageAlphaBlending($image_dest, false);
             } elseif (!$istruecolor) {
                 ImagePaletteCopy($image_dest, $image);
             } else {
                 ImageColorTransparent($image_dest, ImageColorAllocate($image_dest, 0, 0, 0));
                 ImageAlphaBlending($image_dest, false);
                 ImageSaveAlpha($image_dest, true);
             }
             ImageCopyResized($image_dest, $image, 0, 0, $srcx, $srcy, $new_iw, $new_ih, $srcwid, $srchei);
             $iqual_png = 100 - $iqual;
             if (substr(phpversion(), 0, 1) >= 5) {
                 $iqual_png = intval(($iqual - 10) / 10);
             }
             ob_start();
             // start a new output buffer
             Imagepng($image_dest, NULL, $iqual_png);
             $buffer = ob_get_contents();
             ob_end_clean();
             // stop this output buffer
         }
         if (isset($buffer) && $buffer != "") {
             JFile::write($idir . '/' . $iname, $buffer);
             unset($buffer);
         }
         if (isset($image)) {
             imagedestroy($image);
         }
         if (isset($image_dest)) {
             imagedestroy($image_dest);
         }
     }
     //utf8_encode and rawurlencode file name
     $iname = rawurlencode(utf8_encode($iname));
     //return path/filename/type/width/height
     return $thenewimage = array($idir . '/' . $iname, $iname, $itype, $new_iw, $new_ih);
 }
Exemplo n.º 19
0
 public function WatermarkOverlay(&$gdimg_dest, &$img_watermark, $alignment = '*', $opacity = 50, $margin_x = 5, $margin_y = null)
 {
     if (is_resource($gdimg_dest) && is_resource($img_watermark)) {
         $watermark_source_x = 0;
         $watermark_source_y = 0;
         $img_source_width = ImageSX($gdimg_dest);
         $img_source_height = ImageSY($gdimg_dest);
         $watermark_source_width = ImageSX($img_watermark);
         $watermark_source_height = ImageSY($img_watermark);
         $watermark_opacity_percent = max(0, min(100, $opacity));
         $margin_y = is_null($margin_y) ? $margin_x : $margin_y;
         $watermark_margin_x = $margin_x > 0 && $margin_x < 1 ? round((1 - $margin_x) * $img_source_width) : $margin_x;
         $watermark_margin_y = $margin_y > 0 && $margin_y < 1 ? round((1 - $margin_y) * $img_source_height) : $margin_y;
         if (preg_match('#^([0-9\\.\\-]*)x([0-9\\.\\-]*)$#i', $alignment, $matches)) {
             $watermark_destination_x = intval($matches[1]);
             $watermark_destination_y = intval($matches[2]);
         } else {
             switch ($alignment) {
                 case '*':
                     if ($gdimg_tiledwatermark = phpthumb_functions::ImageCreateFunction($img_source_width, $img_source_height)) {
                         ImageAlphaBlending($gdimg_tiledwatermark, false);
                         ImageSaveAlpha($gdimg_tiledwatermark, true);
                         $text_color_transparent = phpthumb_functions::ImageColorAllocateAlphaSafe($gdimg_tiledwatermark, 255, 0, 255, 127);
                         ImageFill($gdimg_tiledwatermark, 0, 0, $text_color_transparent);
                         // set the tiled image transparent color to whatever the untiled image transparency index is
                         //						ImageColorTransparent($gdimg_tiledwatermark, ImageColorTransparent($img_watermark));
                         // a "cleaner" way of doing it, but can't handle the margin feature :(
                         //						ImageSetTile($gdimg_tiledwatermark, $img_watermark);
                         //						ImageFill($gdimg_tiledwatermark, 0, 0, IMG_COLOR_TILED);
                         //						break;
                         //						ImageFill($gdimg_tiledwatermark, 0, 0, ImageColorTransparent($gdimg_tiledwatermark));
                         // tile the image as many times as can fit
                         for ($x = $watermark_margin_x; $x < $img_source_width + $watermark_source_width; $x += $watermark_source_width + $watermark_margin_x) {
                             for ($y = $watermark_margin_y; $y < $img_source_height + $watermark_source_height; $y += $watermark_source_height + $watermark_margin_y) {
                                 ImageCopy($gdimg_tiledwatermark, $img_watermark, $x, $y, 0, 0, min($watermark_source_width, $img_source_width - $x - $watermark_margin_x), min($watermark_source_height, $img_source_height - $y - $watermark_margin_y));
                             }
                         }
                         $watermark_source_width = ImageSX($gdimg_tiledwatermark);
                         $watermark_source_height = ImageSY($gdimg_tiledwatermark);
                         $watermark_destination_x = 0;
                         $watermark_destination_y = 0;
                         ImageDestroy($img_watermark);
                         $img_watermark = $gdimg_tiledwatermark;
                     }
                     break;
                 case 'T':
                     $watermark_destination_x = round($img_source_width / 2 - $watermark_source_width / 2 + $watermark_margin_x);
                     $watermark_destination_y = $watermark_margin_y;
                     break;
                 case 'B':
                     $watermark_destination_x = round($img_source_width / 2 - $watermark_source_width / 2 + $watermark_margin_x);
                     $watermark_destination_y = $img_source_height - $watermark_source_height - $watermark_margin_y;
                     break;
                 case 'L':
                     $watermark_destination_x = $watermark_margin_x;
                     $watermark_destination_y = round($img_source_height / 2 - $watermark_source_height / 2 + $watermark_margin_y);
                     break;
                 case 'R':
                     $watermark_destination_x = $img_source_width - $watermark_source_width - $watermark_margin_x;
                     $watermark_destination_y = round($img_source_height / 2 - $watermark_source_height / 2 + $watermark_margin_y);
                     break;
                 case 'C':
                     $watermark_destination_x = round($img_source_width / 2 - $watermark_source_width / 2);
                     $watermark_destination_y = round($img_source_height / 2 - $watermark_source_height / 2);
                     break;
                 case 'TL':
                     $watermark_destination_x = $watermark_margin_x;
                     $watermark_destination_y = $watermark_margin_y;
                     break;
                 case 'TR':
                     $watermark_destination_x = $img_source_width - $watermark_source_width - $watermark_margin_x;
                     $watermark_destination_y = $watermark_margin_y;
                     break;
                 case 'BL':
                     //echo '<pre>';
                     ////var_dump($watermark_destination_x);
                     ////var_dump($watermark_destination_y);
                     //var_dump($watermark_margin_x);
                     //var_dump($img_source_height);
                     //var_dump($watermark_source_height);
                     //var_dump($watermark_margin_y);
                     $watermark_destination_x = $watermark_margin_x;
                     $watermark_destination_y = $img_source_height - $watermark_source_height - $watermark_margin_y;
                     break;
                 case 'BR':
                 default:
                     $watermark_destination_x = $img_source_width - $watermark_source_width - $watermark_margin_x;
                     $watermark_destination_y = $img_source_height - $watermark_source_height - $watermark_margin_y;
                     break;
             }
         }
         ImageAlphaBlending($gdimg_dest, false);
         ImageSaveAlpha($gdimg_dest, true);
         ImageSaveAlpha($img_watermark, true);
         phpthumb_functions::ImageCopyRespectAlpha($gdimg_dest, $img_watermark, $watermark_destination_x, $watermark_destination_y, 0, 0, $watermark_source_width, $watermark_source_height, $watermark_opacity_percent);
         return true;
     }
     return false;
 }
Exemplo n.º 20
0
function ImageResize($image, $paras){
	$xcount = ImageSX($image);
	$ycount = ImageSY($image);
	
	if ($paras["width"]){
		$newwidth = $paras["width"];
	}
	
	if ($paras["height"]){
		$newheight = $paras["height"];
	}
	
	if ($newwidth && !$newheight){
		$newheight = round($ycount / ($xcount / $newwidth));
	}
	
	if ($newheight && !$newwidth){
		$newwidth = round($xcount / ($ycount / $newheight));
	}
	
	$newimage = ImageCreateTrueColor($newwidth, $newheight);
	ImageAlphaBlending($newimage, false);
	ImageSaveAlpha($newimage, true);
	
	ImageCopyResampled($newimage, $image, 0, 0, 0, 0, $newwidth, $newheight, $xcount, $ycount);
	return $newimage;
}
Exemplo n.º 21
0
 /**
  * Creates Apple-style reflection under image, optionally adding a border to main image
  *
  * @param int $percent
  * @param int $reflection
  * @param int $white
  * @param bool $border
  * @param string $borderColor
  */
 function createReflection($percent, $reflection, $white, $border = true, $borderColor = '#a4a4a4')
 {
     $width = $this->currentDimensions['width'];
     $height = $this->currentDimensions['height'];
     $reflectionHeight = intval($height * ($reflection / 100));
     $newHeight = $height + $reflectionHeight;
     $reflectedPart = $height * ($percent / 100);
     $this->workingImage = ImageCreateTrueColor($width, $newHeight);
     ImageAlphaBlending($this->workingImage, true);
     $colorToPaint = ImageColorAllocateAlpha($this->workingImage, 255, 255, 255, 0);
     ImageFilledRectangle($this->workingImage, 0, 0, $width, $newHeight, $colorToPaint);
     imagecopyresampled($this->workingImage, $this->newImage, 0, 0, 0, $reflectedPart, $width, $reflectionHeight, $width, $height - $reflectedPart);
     $this->imageFlipVertical();
     imagecopy($this->workingImage, $this->newImage, 0, 0, 0, 0, $width, $height);
     imagealphablending($this->workingImage, true);
     for ($i = 0; $i < $reflectionHeight; $i++) {
         $colorToPaint = imagecolorallocatealpha($this->workingImage, 255, 255, 255, ($i / $reflectionHeight * -1 + 1) * $white);
         imagefilledrectangle($this->workingImage, 0, $height + $i, $width, $height + $i, $colorToPaint);
     }
     if ($border == true) {
         $rgb = $this->hex2rgb($borderColor, false);
         $colorToPaint = imagecolorallocate($this->workingImage, $rgb[0], $rgb[1], $rgb[2]);
         imageline($this->workingImage, 0, 0, $width, 0, $colorToPaint);
         //top line
         imageline($this->workingImage, 0, $height, $width, $height, $colorToPaint);
         //bottom line
         imageline($this->workingImage, 0, 0, 0, $height, $colorToPaint);
         //left line
         imageline($this->workingImage, $width - 1, 0, $width - 1, $height, $colorToPaint);
         //right line
     }
     $this->oldImage = $this->workingImage;
     $this->newImage = $this->workingImage;
     $this->currentDimensions['width'] = $width;
     $this->currentDimensions['height'] = $newHeight;
 }
Exemplo n.º 22
0
 /**
  * Set clipping to occur
  * 
  * Parameter array:
  * 
  * 'x0': int X point of Upper-left corner
  * 'y0': int X point of Upper-left corner
  * 'x1': int X point of lower-right corner
  * 'y1': int Y point of lower-right corner
  */
 function setClipping($params = false)
 {
     if ($params === false) {
         $index = count($this->_clipping) - 1;
         if (isset($this->_clipping[$index])) {
             $params = $this->_clipping[$index];
             $canvas = $params['canvas'];
             ImageCopy($canvas, $this->_canvas, min($params['x0'], $params['x1']), min($params['y0'], $params['y1']), min($params['x0'], $params['x1']), min($params['y0'], $params['y1']), abs($params['x1'] - $params['x0'] + 1), abs($params['y1'] - $params['y0'] + 1));
             $this->_canvas = $canvas;
             unset($this->_clipping[$index]);
         }
     } else {
         $params['canvas'] = $this->_canvas;
         if ($this->_gd2) {
             $this->_canvas = ImageCreateTrueColor($this->_width, $this->_height);
             if ($this->_alpha) {
                 ImageAlphaBlending($this->_canvas, true);
             }
         } else {
             $this->_canvas = ImageCreate($this->_width, $this->_height);
         }
         if ($this->_gd2 && $this->_antialias === 'native') {
             ImageAntialias($this->_canvas, true);
         }
         ImageCopy($this->_canvas, $params['canvas'], 0, 0, 0, 0, $this->_width, $this->_height);
         $this->_clipping[count($this->_clipping)] = $params;
     }
 }
Exemplo n.º 23
0
/**
 * Generate a thumbnail version of a particular image.
 *
 * @param string The file system path of the image to create a thumbnail of.
 * @param string The file system path of the name/location to save the thumbnail.
 * @param int The maximum width of the image.
 * @param boolean If the image is small enough, copy it to destLocation, otherwise just return.
 */
function GenerateThumbnail($sourceLocation, $destLocation, $maxWidth, $maxHeight = null)
{
    if (is_null($maxHeight)) {
        $maxHeight = $maxWidth;
    }
    if ($sourceLocation == '' || !file_exists($sourceLocation)) {
        return false;
    } else {
        if (!is_dir(dirname($destLocation)) || !is_writable(dirname($destLocation))) {
            return false;
        }
    }
    // A list of thumbnails too
    $tmp = explode(".", $sourceLocation);
    $ext = isc_strtolower($tmp[count($tmp) - 1]);
    $attribs = @getimagesize($sourceLocation);
    $srcWidth = $attribs[0];
    $srcHeight = $attribs[1];
    if (!is_array($attribs)) {
        return false;
    }
    // Check if we have enough available memory to create this image - if we don't, attempt to bump it up
    SetImageFileMemLimit($sourceLocation);
    if ($ext == "jpg") {
        $srcImg = @imagecreatefromjpeg($sourceLocation);
    } else {
        if ($ext == "gif") {
            $srcImg = @imagecreatefromgif($sourceLocation);
            if (!function_exists("imagegif")) {
                $gifHack = 1;
            }
        } else {
            $srcImg = @imagecreatefrompng($sourceLocation);
        }
    }
    if (!$srcImg) {
        return false;
    }
    // This image dimensions. Simply copy and return
    if ($srcWidth <= $maxWidth && $srcHeight <= $maxHeight) {
        @imagedestroy($srcImg);
        if ($sourceLocation != $destLocation && copy($sourceLocation, $destLocation)) {
            return true;
        }
    }
    // Make sure the thumb has a constant height
    $width = $srcWidth;
    $thumbWidth = $srcWidth;
    $height = $srcHeight;
    $thumbHeight = $srcHeight;
    if ($width > $maxWidth) {
        $thumbWidth = $maxWidth;
        $thumbHeight = $maxWidth / $srcWidth * $srcHeight;
    } else {
        $thumbHeight = $maxHeight;
        $thumbWidth = $maxHeight / $srcHeight * $srcWidth;
    }
    $thumbImage = @imagecreatetruecolor($thumbWidth, $thumbHeight);
    if ($ext == "gif" && !isset($gifHack)) {
        $colorTransparent = @imagecolortransparent($srcImg);
        @imagepalettecopy($srcImg, $thumbImage);
        @imagecolortransparent($thumbImage, $colorTransparent);
        @imagetruecolortopalette($thumbImage, true, 256);
    } else {
        if ($ext == "png") {
            @ImageColorTransparent($thumbImage, @ImageColorAllocate($thumbImage, 0, 0, 0));
            @ImageAlphaBlending($thumbImage, false);
        }
    }
    @imagecopyresampled($thumbImage, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $srcWidth, $srcHeight);
    if ($ext == "jpg") {
        @imagejpeg($thumbImage, $destLocation, 100);
    } else {
        if ($ext == "gif") {
            if (isset($gifHack) && $gifHack == true) {
                $thumbFile = isc_substr($thumbFile, 0, -3) . "jpg";
                @imagejpeg($thumbImage, $destLocation, 100);
            } else {
                @imagegif($thumbImage, $destLocation);
            }
        } else {
            @imagepng($thumbImage, $destLocation);
        }
    }
    @imagedestroy($thumbImage);
    @imagedestroy($srcImg);
    // Change the permissions on the thumbnail file
    isc_chmod($destLocation, ISC_WRITEABLE_FILE_PERM);
    return true;
}
function nzshpcrt_display_preview_image()
{
    global $wpdb;
    if ($_GET['wpsc_request_image'] == 'true' || is_numeric($_GET['productid']) || is_numeric($_GET['image_id']) || isset($_GET['image_name'])) {
        if (function_exists("getimagesize")) {
            if (is_numeric($_GET['productid'])) {
                $product_id = (int) $_GET['productid'];
                $image_data = $wpdb->get_var("SELECT `image` FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `id`='{$product_id}' LIMIT 1");
                if (is_numeric($image_data)) {
                    $image = $wpdb->get_var("SELECT `image` FROM `" . WPSC_TABLE_PRODUCT_IMAGES . "` WHERE `id` = '{$image_data}' LIMIT 1");
                    $imagepath = WPSC_IMAGE_DIR . $image;
                } else {
                    $imagepath = WPSC_IMAGE_DIR . $imagedata['image'];
                }
            } else {
                if ($_GET['image_id']) {
                    $image_id = (int) $_GET['image_id'];
                    $results = $wpdb->get_row("SELECT `image`,`product_id` FROM `" . WPSC_TABLE_PRODUCT_IMAGES . "` WHERE `id` = '{$image_id}' LIMIT 1");
                    $image = $results->image;
                    $pid = $results->product_id;
                    $thumbnail_info = $wpdb->get_row("SELECT `thumbnail_state`,`image` FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `id` = '{$pid}' LIMIT 1");
                    $thumbnail_state = $thumbnail_info->thumbnail_state;
                    $thumbnail_image = $thumbnail_info->image;
                    if ($thumbnail_state == 3 && $image_id == $thumbnail_image) {
                        $imagepath = WPSC_THUMBNAIL_DIR . $image;
                    } else {
                        $imagepath = WPSC_IMAGE_DIR . $image;
                    }
                } else {
                    if ($_GET['image_name']) {
                        $image = basename($_GET['image_name']);
                        $imagepath = WPSC_USER_UPLOADS_DIR . $image;
                    } else {
                        if ($_GET['category_id']) {
                            $category_id = absint($_GET['category_id']);
                            $image = $wpdb->get_var("SELECT `image` FROM `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` WHERE `id` = '{$category_id}' LIMIT 1");
                            if ($image != '') {
                                $imagepath = WPSC_CATEGORY_DIR . $image;
                            }
                        }
                    }
                }
            }
            if (!is_file($imagepath)) {
                $imagepath = WPSC_FILE_PATH . "/images/no-image-uploaded.gif";
            }
            $image_size = @getimagesize($imagepath);
            if (is_numeric($_GET['height']) && is_numeric($_GET['width'])) {
                $height = (int) $_GET['height'];
                $width = (int) $_GET['width'];
            } else {
                $width = $image_size[0];
                $height = $image_size[1];
            }
            if (!($height > 0 && $height <= 1024 && $width > 0 && $width <= 1024)) {
                $width = $image_size[0];
                $height = $image_size[1];
            }
            if ($product_id > 0) {
                $cache_filename = basename("product_{$product_id}_{$height}x{$width}");
            } else {
                if ($category_id > 0) {
                    $cache_filename = basename("category_{$category_id}_{$height}x{$width}");
                } else {
                    $cache_filename = basename("product_img_{$image_id}_{$height}x{$width}");
                }
            }
            //echo "<pre>".print_r($_GET, true)."</pre>";
            //exit($cache_filename);
            $imagetype = @getimagesize($imagepath);
            $use_cache = false;
            switch ($imagetype[2]) {
                case IMAGETYPE_JPEG:
                    $extension = ".jpg";
                    break;
                case IMAGETYPE_GIF:
                    $extension = ".gif";
                    break;
                case IMAGETYPE_PNG:
                    $extension = ".png";
                    break;
            }
            if (file_exists(WPSC_CACHE_DIR . $cache_filename . $extension)) {
                $original_modification_time = filemtime($imagepath);
                $cache_modification_time = filemtime(WPSC_CACHE_DIR . $cache_filename . $extension);
                if ($original_modification_time < $cache_modification_time) {
                    $use_cache = true;
                }
            }
            if ($use_cache === true) {
                $cache_url = WPSC_CACHE_URL;
                if (is_ssl()) {
                    $cache_url = str_replace("http://", "https://", $cache_url);
                }
                header("Location: " . $cache_url . $cache_filename . $extension);
                exit('');
            } else {
                switch ($imagetype[2]) {
                    case IMAGETYPE_JPEG:
                        //$extension = ".jpg";
                        $src_img = imagecreatefromjpeg($imagepath);
                        $pass_imgtype = true;
                        break;
                    case IMAGETYPE_GIF:
                        //$extension = ".gif";
                        $src_img = imagecreatefromgif($imagepath);
                        $pass_imgtype = true;
                        break;
                    case IMAGETYPE_PNG:
                        //$extension = ".png";
                        $src_img = imagecreatefrompng($imagepath);
                        $pass_imgtype = true;
                        break;
                    default:
                        $pass_imgtype = false;
                        break;
                }
                if ($pass_imgtype === true) {
                    $source_w = imagesx($src_img);
                    $source_h = imagesy($src_img);
                    //Temp dimensions to crop image properly
                    $temp_w = $width;
                    $temp_h = $height;
                    // select our scaling method
                    $scaling_method = 'cropping';
                    //list($source_h, $source_w) = array($source_w, $source_h);
                    // set both offsets to zero
                    $offset_x = $offset_y = 0;
                    // Here are the scaling methods, non-cropping causes black lines in tall images, but doesnt crop images.
                    switch ($scaling_method) {
                        case 'cropping':
                            // if the image is wider than it is high and at least as wide as the target width.
                            if ($source_h <= $source_w) {
                                if ($height < $width) {
                                    $temp_h = $width / $source_w * $source_h;
                                } else {
                                    $temp_w = $height / $source_h * $source_w;
                                }
                            } else {
                                $temp_h = $width / $source_w * $source_h;
                            }
                            break;
                        case 'non-cropping':
                        default:
                            if ($height < $width) {
                                $temp_h = $width / $source_w * $source_h;
                            } else {
                                $temp_w = $height / $source_h * $source_w;
                            }
                            break;
                    }
                    // Create temp resized image
                    $temp_img = ImageCreateTrueColor($temp_w, $temp_h);
                    $bgcolor = ImageColorAllocate($temp_img, 255, 255, 255);
                    ImageFilledRectangle($temp_img, 0, 0, $temp_w, $temp_h, $bgcolor);
                    ImageAlphaBlending($temp_img, TRUE);
                    ImageCopyResampled($temp_img, $src_img, 0, 0, 0, 0, $temp_w, $temp_h, $source_w, $source_h);
                    $dst_img = ImageCreateTrueColor($width, $height);
                    $bgcolor = ImageColorAllocate($dst_img, 255, 255, 255);
                    ImageFilledRectangle($dst_img, 0, 0, $width, $height, $bgcolor);
                    ImageAlphaBlending($dst_img, TRUE);
                    if ($imagetype[2] == IMAGETYPE_PNG || $imagetype[2] == IMAGETYPE_GIF) {
                        //imagecolortransparent($dst_img, $bgcolor);
                    }
                    // X & Y Offset to crop image properly
                    if ($temp_w < $width) {
                        $w1 = $width / 2 - $temp_w / 2;
                    } else {
                        if ($temp_w == $width) {
                            $w1 = 0;
                        } else {
                            $w1 = $width / 2 - $temp_w / 2;
                        }
                    }
                    if ($temp_h < $height) {
                        $h1 = $height / 2 - $temp_h / 2;
                    } else {
                        if ($temp_h == $height) {
                            $h1 = 0;
                        } else {
                            $h1 = $height / 2 - $temp_h / 2;
                        }
                    }
                    switch ($scaling_method) {
                        case 'cropping':
                            ImageCopy($dst_img, $temp_img, $w1, $h1, 0, 0, $temp_w, $temp_h);
                            break;
                        case 'non-cropping':
                        default:
                            ImageCopy($dst_img, $temp_img, 0, 0, 0, 0, $temp_w, $temp_h);
                            break;
                    }
                    $image_quality = wpsc_image_quality();
                    ImageAlphaBlending($dst_img, false);
                    switch ($imagetype[2]) {
                        case IMAGETYPE_JPEG:
                            header("Content-type: image/jpeg");
                            imagejpeg($dst_img);
                            imagejpeg($dst_img, WPSC_CACHE_DIR . $cache_filename . ".jpg", $image_quality);
                            @chmod(WPSC_CACHE_DIR . $cache_filename . ".jpg", 0775);
                            break;
                        case IMAGETYPE_GIF:
                            header("Content-type: image/gif");
                            ImagePNG($dst_img);
                            ImagePNG($dst_img, WPSC_CACHE_DIR . $cache_filename . ".gif");
                            @chmod(WPSC_CACHE_DIR . $cache_filename . ".gif", 0775);
                            break;
                        case IMAGETYPE_PNG:
                            header("Content-type: image/png");
                            ImagePNG($dst_img);
                            ImagePNG($dst_img, WPSC_CACHE_DIR . $cache_filename . ".png");
                            @chmod(WPSC_CACHE_DIR . $cache_filename . ".png", 0775);
                            break;
                        default:
                            $pass_imgtype = false;
                            break;
                    }
                    exit;
                }
            }
        }
    }
}
Exemplo n.º 25
0
 function SetAlphaBlending($aFlg = true)
 {
     ImageAlphaBlending($this->img, $aFlg);
 }
Exemplo n.º 26
0
function reduire_image($userfile_name)
{
    global $pmb_vignette_x;
    global $pmb_vignette_y;
    global $base_path;
    global $pmb_curl_available;
    if (!$pmb_vignette_x) {
        $pmb_vignette_x = 100;
    }
    if (!$pmb_vignette_y) {
        $pmb_vignette_y = 100;
    }
    $src_image = '';
    if (file_exists("{$base_path}/temp/{$userfile_name}")) {
        $bidon = "{$base_path}/temp/{$userfile_name}";
        $source_file = $bidon . "[0]";
    } else {
        $bidon = $userfile_name;
        //Il s'agit d'une url, on copie le fichier en local
        $nom_temp = session_id() . microtime();
        $nom_temp = str_replace(' ', '_', $nom_temp);
        $nom_temp = str_replace('.', '_', $nom_temp);
        $fichier_tmp = "{$base_path}/temp/" . $nom_temp;
        if ($pmb_curl_available) {
            $aCurl = new Curl();
            $aCurl->save_file_name = $fichier_tmp;
            $aCurl->get($userfile_name);
        } else {
            $handle = fopen($userfile_name, "rb");
            $filecontent = stream_get_contents($handle);
            fclose($handle);
            $fd = fopen($fichier_tmp, "w");
            fwrite($fd, $filecontent);
            fclose($fd);
        }
        $source_file = $fichier_tmp . "[0]";
    }
    $error = true;
    if (extension_loaded('imagick')) {
        mysql_set_wait_timeout(3600);
        $error = false;
        try {
            $img = new Imagick();
            $img->readImage($source_file);
            if ($img->getImageWidth() > $pmb_vignette_x || $img->getImageHeight() > $pmb_vignette_y) {
                // Si l'image est trop grande on la réduit
                $img->thumbnailimage($pmb_vignette_x, $pmb_vignette_y, true);
            }
            $img->setImageFormat("png");
            $img->setCompression(Imagick::COMPRESSION_LZW);
            $img->setCompressionQuality(90);
            $contenu_vignette = $img->getImageBlob();
        } catch (Exception $ex) {
            $error = true;
        }
        unlink($fichier_tmp);
    }
    if ($error) {
        $size = @getimagesize($bidon);
        /*   ".gif"=>"1",
        	         ".jpg"=>"2",
        	         ".jpeg"=>"2",
        	         ".png"=>"3",
        	         ".swf"=>"4",
        	         ".psd"=>"5",
        	         ".bmp"=>"6");
        		*/
        switch ($size[2]) {
            case 1:
                $src_img = imagecreatefromgif($bidon);
                break;
            case 2:
                $src_img = imagecreatefromjpeg($bidon);
                break;
            case 3:
                $src_img = imagecreatefrompng($bidon);
                break;
            case 6:
                $src_img = imagecreatefromwbmp($bidon);
                break;
            default:
                break;
        }
        $erreur_vignette = 0;
        if ($src_img) {
            $rs = $pmb_vignette_x / $pmb_vignette_y;
            $taillex = imagesx($src_img);
            $tailley = imagesy($src_img);
            if (!$taillex || !$tailley) {
                return "";
            }
            if ($taillex > $pmb_vignette_x || $tailley > $pmb_vignette_y) {
                $r = $taillex / $tailley;
                if ($r < 1 && $rs < 1) {
                    //Si x plus petit que y et taille finale portrait
                    //Si le format final est plus large en proportion
                    if ($rs > $r) {
                        $new_h = $pmb_vignette_y;
                        $new_w = $new_h * $r;
                    } else {
                        $new_w = $pmb_vignette_x;
                        $new_h = $new_w / $r;
                    }
                } else {
                    if ($r < 1 && $rs >= 1) {
                        //Si x plus petit que y et taille finale paysage
                        $new_h = $pmb_vignette_y;
                        $new_w = $new_h * $r;
                    } else {
                        if ($r > 1 && $rs < 1) {
                            //Si x plus grand que y et taille finale portrait
                            $new_w = $pmb_vignette_x;
                            $new_h = $new_w / $r;
                        } else {
                            //Si x plus grand que y et taille finale paysage
                            if ($rs < $r) {
                                $new_w = $pmb_vignette_x;
                                $new_h = $new_w / $r;
                            } else {
                                $new_h = $pmb_vignette_y;
                                $new_w = $new_h * $r;
                            }
                        }
                    }
                }
            } else {
                $new_h = $tailley;
                $new_w = $taillex;
            }
            $dst_img = imagecreatetruecolor($pmb_vignette_x, $pmb_vignette_y);
            ImageSaveAlpha($dst_img, true);
            ImageAlphaBlending($dst_img, false);
            imagefilledrectangle($dst_img, 0, 0, $pmb_vignette_x, $pmb_vignette_y, imagecolorallocatealpha($dst_img, 0, 0, 0, 127));
            imagecopyresized($dst_img, $src_img, round(($pmb_vignette_x - $new_w) / 2), round(($pmb_vignette_y - $new_h) / 2), 0, 0, $new_w, $new_h, ImageSX($src_img), ImageSY($src_img));
            imagepng($dst_img, "{$base_path}/temp/" . SESSid);
            $fp = fopen("{$base_path}/temp/" . SESSid, "r");
            $contenu_vignette = fread($fp, filesize("{$base_path}/temp/" . SESSid));
            if (!$fp || $contenu_vignette == "") {
                $erreur_vignette++;
            }
            fclose($fp);
            unlink("{$base_path}/temp/" . SESSid);
        } else {
            $contenu_vignette = '';
        }
    }
    return $contenu_vignette;
}
 static function createWatermarkImage($source_dir, $destination_dir, $file_name, $delete_existing_file = false, $watermark_text = '', $args = array())
 {
     global $wp_photo_gallery;
     if ($watermark_text === '') {
         $watermark_text = ' ';
         //get_site_url();
     }
     $watermark_image_name = 'watermark_' . $file_name;
     $dest = $destination_dir . $watermark_image_name;
     if (file_exists($dest)) {
         if ($delete_existing_file === false) {
             return;
         }
     }
     $sourch_file = $source_dir . $file_name;
     $image_info = getimagesize($sourch_file);
     list($width, $height) = $image_info;
     $mime_type = strtolower($image_info['mime']);
     $desired_height = isset($args['watermark_height']) ? $args['watermark_height'] : '';
     $desired_width = isset($args['watermark_width']) ? $args['watermark_width'] : '';
     $font_size = isset($args['watermark_font_size']) ? $args['watermark_font_size'] : '';
     $watermark_placement = isset($args['watermark_placement']) ? $args['watermark_placement'] : '0';
     $watermark_opacity = isset($args['watermark_opacity']) ? $args['watermark_opacity'] : '35';
     //$watermark_colour = isset($args['watermark_colour'])?$args['watermark_colour']:'ffffff'; //TODO - introduce in settings using a colour picker
     if ($desired_height != '') {
         //we have a portrait image so use the height as the maximum dimension
         if ($desired_height > $height) {
             $desired_height = $height;
         }
         //Check to make sure the watermarked image is not larger than the original
         $desired_width = floor($width * ($desired_height / $height));
     } else {
         //we have a landscape image so use the width as the maximum dimension
         if (empty($desired_width)) {
             $desired_width = 600;
         }
         if ($desired_width > $width) {
             $desired_width = $width;
         }
         //Check to make sure the watermarked image is not larger than the original
         $desired_height = floor($height * ($desired_width / $width));
     }
     if (empty($font_size)) {
         $font_size = 35;
     }
     if ($mime_type == 'image/jpeg' || $mime_type == 'image/pjpeg') {
         $image = imagecreatefromjpeg($sourch_file);
     } else {
         if ($mime_type == 'image/png') {
             $image = imagecreatefrompng($sourch_file);
         }
     }
     $font = WP_PHOTO_PATH . '/fonts' . DIRECTORY_SEPARATOR . 'arial.ttf';
     $TextSize = ImageTTFBBox($font_size, 0, $font, $watermark_text) or die;
     $TextWidth = abs($TextSize[2]) + abs($TextSize[0]) + 8;
     //Added an extra 8 pixels because otherwise the watermark text appeared slightly cut-off on the RHS
     $TextHeight = abs($TextSize[7]) + abs($TextSize[1]);
     // Create Image for Text
     $image_p = ImageCreateTrueColor($TextWidth, $TextHeight);
     ImageSaveAlpha($image_p, true);
     ImageAlphaBlending($image_p, false);
     $bgText = imagecolorallocatealpha($image_p, 255, 255, 255, 127);
     imagefill($image_p, 0, 0, $bgText);
     $watermark_transparency = 127 - $watermark_opacity * 1.27;
     $color = 'ffffff';
     //TODO - introduce in settings using a colour picker
     $rgb = WPPGPhotoGallery::hex2rgb($color, false);
     $TextColor = imagecolorallocatealpha($image_p, $rgb[0], $rgb[1], $rgb[2], $watermark_transparency);
     // Create Text on image
     imagettftext($image_p, $font_size, 0, 0, abs($TextSize[5]), $TextColor, $font, $watermark_text);
     $watermark_img_path = $image_p;
     imagealphablending($image_p, false);
     imagesavealpha($image_p, true);
     $sourcefile_width = imageSX($image);
     $sourcefile_height = imageSY($image);
     $watermarkfile_width = imageSX($image_p);
     $watermarkfile_height = imageSY($image_p);
     if ($watermark_placement == '0') {
         //Centre
         $dest_x = $sourcefile_width / 2 - $watermarkfile_width / 2;
         $dest_y = $sourcefile_height / 2 - $watermarkfile_height / 2;
     } elseif ($watermark_placement == '1') {
         //Top Left
         $dest_x = 5;
         $dest_y = 5;
     } elseif ($watermark_placement == '2') {
         //Top Right
         $dest_x = $sourcefile_width - $watermarkfile_width - 5;
         $dest_y = 5;
     } elseif ($watermark_placement == '3') {
         //Bottom Right
         $dest_x = $sourcefile_width - $watermarkfile_width - 5;
         $dest_y = $sourcefile_height - $watermarkfile_height - 5;
     } elseif ($watermark_placement == '4') {
         //Bottom Left
         $dest_x = 5;
         $dest_y = $sourcefile_height - $watermarkfile_height - 5;
     } else {
         //default - Centre
         $dest_x = $sourcefile_width / 2 - $watermarkfile_width / 2;
         $dest_y = $sourcefile_height / 2 - $watermarkfile_height / 2;
     }
     if ($watermark_placement != '5') {
         //Place the image according to the co-ordinates calculated from above
         imagecopy($image, $image_p, $dest_x, $dest_y, 0, 0, $watermarkfile_width, $watermarkfile_height);
     } else {
         //Display watermark text as repeated grid
         $top = 20;
         while ($top < $sourcefile_height) {
             $left = 10;
             while ($left < $sourcefile_width) {
                 imagecopy($image, $image_p, $left, $top, 0, 0, $TextWidth, $TextHeight);
                 $left = $left + $TextWidth + 50;
             }
             $top = $top + $TextHeight + 50;
         }
     }
     /* create the physical watermarked image to its destination */
     imagejpeg($image, $dest, 100);
     imagedestroy($image);
     //clean up some memory
     $resized = image_make_intermediate_size($source_dir . $watermark_image_name, $desired_width, $desired_height);
     //Use the WP function to resize the watermarked image to that specified in the settings
     if ($resized === false) {
         $wp_photo_gallery->debug_logger->log_debug('WPPGPhotoGallery::createWatermarkImage - image_make_intermediate_size failed and returned false!', 4);
     } else {
         rename($source_dir . $resized['file'], $source_dir . $watermark_image_name);
         //Since the above WP function uses a different naming convention we will change the name back to our convention
     }
 }
Exemplo n.º 28
0
 public function _AutoGenerateInsThumb($ImageName, $Size = "thumb", $OverrideExisting = false)
 {
     // Takes the filename of an image already uploaded into the
     // image directory, generates a thumbnal from it, stores it
     // in the image directory and returns its name
     $imgFile = realpath(ISC_BASE_PATH . "/install_images");
     $imgFile .= "/" . $ImageName;
     if ($ImageName == '' || !file_exists($imgFile)) {
         return false;
     }
     // A list of thumbnails too
     $tmp = explode(".", $imgFile);
     $ext = isc_strtolower($tmp[count($tmp) - 1]);
     // If overriding the existing image, set the output filename to the input filename
     //Large and medium size images by Simha
     if ($Size == 'large') {
         $thumbFileName = $ImageName;
     } else {
         if ($Size == 'medium') {
             $thumbFileName = GenRandFileName($ImageName, $Size);
         } else {
             if ($OverrideExisting == true) {
                 $thumbFileName = $ImageName;
             } else {
                 $thumbFileName = GenRandFileName($ImageName, $Size);
             }
         }
     }
     $attribs = @getimagesize($imgFile);
     $width = $attribs[0];
     $height = $attribs[1];
     if (!is_array($attribs)) {
         return false;
     }
     // Check if we have enough available memory to create this image - if we don't, attempt to bump it up
     setImageFileMemLimit($imgFile);
     $thumbFile = realpath(ISC_BASE_PATH . "/install_images");
     $thumbFile .= "/" . $thumbFileName;
     if ($ext == "jpg") {
         $srcImg = @imagecreatefromjpeg($imgFile);
     } else {
         if ($ext == "gif") {
             $srcImg = @imagecreatefromgif($imgFile);
             if (!function_exists("imagegif")) {
                 $gifHack = 1;
             }
         } else {
             $srcImg = @imagecreatefrompng($imgFile);
         }
     }
     if (!$srcImg) {
         return false;
     }
     $srcWidth = @imagesx($srcImg);
     $srcHeight = @imagesy($srcImg);
     //Large and medium size images by Simha
     if ($Size == 'large') {
         $AutoThumbSize = 800;
     } else {
         if ($Size == 'medium') {
             $AutoThumbSize = 70;
         } else {
             if ($Size == "tiny") {
                 $AutoThumbSize = ISC_TINY_THUMB_SIZE;
             } else {
                 $AutoThumbSize = GetConfig('AutoThumbSize');
             }
         }
     }
     // This thumbnail is smaller than the Interspire Shopping Cart dimensions, simply copy the image and return
     if ($srcWidth <= $AutoThumbSize && $srcHeight <= $AutoThumbSize) {
         @imagedestroy($srcImg);
         if ($OverrideExisting == false) {
             @copy($imgFile, $thumbFile);
         }
         return $thumbFileName;
     }
     // Make sure the thumb has a constant height
     $thumbWidth = $width;
     $thumbHeight = $height;
     if ($width > $AutoThumbSize) {
         $thumbWidth = $AutoThumbSize;
         $thumbHeight = ceil($height * ($AutoThumbSize * 100 / $width) / 100);
         $height = $thumbHeight;
         $width = $thumbWidth;
     }
     if ($height > $AutoThumbSize) {
         $thumbHeight = $AutoThumbSize;
         $thumbWidth = ceil($width * ($AutoThumbSize * 100 / $height) / 100);
     }
     $thumbImage = @imagecreatetruecolor($thumbWidth, $thumbHeight);
     if ($ext == "gif" && !isset($gifHack)) {
         $colorTransparent = @imagecolortransparent($srcImg);
         @imagepalettecopy($srcImg, $thumbImage);
         @imagecolortransparent($thumbImage, $colorTransparent);
         @imagetruecolortopalette($thumbImage, true, 256);
     } else {
         if ($ext == "png") {
             @ImageColorTransparent($thumbImage, @ImageColorAllocate($thumbImage, 0, 0, 0));
             @ImageAlphaBlending($thumbImage, false);
         }
     }
     @imagecopyresampled($thumbImage, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $srcWidth, $srcHeight);
     if ($ext == "jpg") {
         @imagejpeg($thumbImage, $thumbFile, 100);
     } else {
         if ($ext == "gif") {
             if (isset($gifHack) && $gifHack == true) {
                 $thumbFile = isc_substr($thumbFile, 0, -3) . "jpg";
                 @imagejpeg($thumbImage, $thumbFile, 100);
             } else {
                 @imagegif($thumbImage, $thumbFile);
             }
         } else {
             @imagepng($thumbImage, $thumbFile);
         }
     }
     @imagedestroy($thumbImage);
     @imagedestroy($srcImg);
     // Change the permissions on the thumbnail file
     isc_chmod($thumbFile, ISC_WRITEABLE_FILE_PERM);
     return $thumbFileName;
 }
Exemplo n.º 29
0
 function SetAlphaBlending($aFlg = true)
 {
     if ($GLOBALS['gd2']) {
         ImageAlphaBlending($this->img, $aFlg);
     } else {
         JpGraphError::Raise('You only seem to have GD 1.x installed. To enable Alphablending requires GD 2.x or higher. Please install GD or make sure the constant USE_GD2 is specified correctly to reflect your installation. By default it tries to autodetect what version of GD you have installed. On some very rare occasions it may falsely detect GD2 where only GD1 is installed. You must then set USE_GD2 to false.');
     }
 }
Exemplo n.º 30
0
 function makeThumbWatermark($width = 128, $height = 128)
 {
     $this->fileCheck();
     $image_info = $this->getInfo($this->src_image_name);
     if (!$image_info) {
         return false;
     }
     $src_image_type = $image_info["type"];
     $img = $this->createImage($src_image_type, $this->src_image_name);
     if (!$img) {
         return false;
     }
     $width = $width == 0 ? $image_info["width"] : $width;
     $height = $height == 0 ? $image_info["height"] : $height;
     $width = $width > $image_info["width"] ? $image_info["width"] : $width;
     $height = $height > $image_info["height"] ? $image_info["height"] : $height;
     $srcW = $image_info["width"];
     $srcH = $image_info["height"];
     if ($srcH * $width > $srcW * $height) {
         $width = round($srcW * $height / $srcH);
     } else {
         $height = round($srcH * $width / $srcW);
     }
     //*
     $src_image = @imagecreatetruecolor($width, $height);
     $white = @imagecolorallocate($src_image, 0xff, 0xff, 0xff);
     @imagecolortransparent($src_image, $white);
     @imagefilltoborder($src_image, 0, 0, $white, $white);
     if ($src_image) {
         ImageCopyResampled($src_image, $img, 0, 0, 0, 0, $width, $height, $image_info["width"], $image_info["height"]);
     } else {
         $src_image = imagecreate($width, $height);
         ImageCopyResized($src_image, $img, 0, 0, 0, 0, $width, $height, $image_info["width"], $image_info["height"]);
     }
     $src_image_w = ImageSX($src_image);
     $src_image_h = ImageSY($src_image);
     if ($this->wm_image_name) {
         $wm_image_info = $this->getInfo($this->wm_image_name);
         if (!$wm_image_info) {
             return false;
         }
         $wm_image_type = $wm_image_info["type"];
         $wm_image = $this->createImage($wm_image_type, $this->wm_image_name);
         $wm_image_w = ImageSX($wm_image);
         $wm_image_h = ImageSY($wm_image);
         $temp_wm_image = $this->getPos($src_image_w, $src_image_h, $this->wm_image_pos, $wm_image);
         if ($this->emboss && function_exists("imagefilter")) {
             imagefilter($wm_image, IMG_FILTER_EMBOSS);
             $bgcolor = imagecolorclosest($wm_image, 0x7f, 0x7f, 0x7f);
             imagecolortransparent($wm_image, $bgcolor);
         }
         if (function_exists("ImageAlphaBlending") && IMAGETYPE_PNG == $wm_image_info['type']) {
             ImageAlphaBlending($src_image, true);
         }
         $wm_image_x = $temp_wm_image["dest_x"];
         $wm_image_y = $temp_wm_image["dest_y"];
         if (IMAGETYPE_PNG == $wm_image_info['type']) {
             imageCopy($src_image, $wm_image, $wm_image_x, $wm_image_y, 0, 0, $wm_image_w, $wm_image_h);
         } else {
             imageCopyMerge($src_image, $wm_image, $wm_image_x, $wm_image_y, 0, 0, $wm_image_w, $wm_image_h, $this->wm_image_transition);
         }
     }
     if ($this->wm_text) {
         $this->wm_text = $this->wm_text;
         $temp_wm_text = $this->getPos($src_image_w, $src_image_h, $this->wm_image_pos);
         $wm_text_x = $temp_wm_text["dest_x"];
         $wm_text_y = $temp_wm_text["dest_y"];
         if (preg_match("/([a-f0-9][a-f0-9])([a-f0-9][a-f0-9])([a-f0-9][a-f0-9])/i", $this->wm_text_color, $color)) {
             $red = hexdec($color[1]);
             $green = hexdec($color[2]);
             $blue = hexdec($color[3]);
             $wm_text_color = imagecolorallocate($src_image, $red, $green, $blue);
         } else {
             $wm_text_color = imagecolorallocate($src_image, 255, 255, 255);
         }
         imagettftext($src_image, $this->wm_text_size, $this->wm_angle, $wm_text_x, $wm_text_y, $wm_text_color, $this->wm_text_font, $this->wm_text);
     }
     if ($this->save_file) {
         switch ($src_image_type) {
             case 1:
                 if ($this->gif_enable) {
                     $src_img = ImageGIF($src_image, $this->save_file);
                 } else {
                     $src_img = ImagePNG($src_image, $this->save_file);
                 }
                 break;
             case 2:
                 $src_img = ImageJPEG($src_image, $this->save_file, $this->jpeg_quality);
                 break;
             case 3:
                 $src_img = ImagePNG($src_image, $this->save_file);
                 break;
             default:
                 $src_img = ImageJPEG($src_image, $this->save_file, $this->jpeg_quality);
                 break;
         }
     } else {
         switch ($src_image_type) {
             case 1:
                 if ($this->gif_enable) {
                     header("Content-type: image/gif");
                     $src_img = ImageGIF($src_image);
                 } else {
                     header("Content-type: image/png");
                     $src_img = ImagePNG($src_image);
                 }
                 break;
             case 2:
                 header("Content-type: image/jpeg");
                 $src_img = ImageJPEG($src_image, "", $this->jpeg_quality);
                 break;
             case 3:
                 header("Content-type: image/png");
                 $src_img = ImagePNG($src_image);
                 break;
             case 6:
                 header("Content-type: image/bmp");
                 $src_img = imagebmp($src_image);
                 break;
             default:
                 header("Content-type: image/jpeg");
                 $src_img = ImageJPEG($src_image, "", $this->jpeg_quality);
                 break;
         }
     }
     imagedestroy($src_image);
     imagedestroy($img);
     return true;
 }