Example #1
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);
}
function TransFormPicture($inputfname, $outputfname, $transform, $backgroundcolor)
{
    $img_in = ImageCreateFromPNG($inputfname);
    $sizex = imagesx($img_in);
    $sizey = imagesy($img_in);
    $img_out = @ImageCreateTrueColor($sizex, $sizey) or die("Cannot create image handle.");
    imagefill($img_out, 0, 0, hexdec($backgroundcolor));
    ImageCopy($img_out, $img_in, 0, 0, 0, 0, $sizex, $sizey);
    for ($x = 0; $x < $sizex; $x++) {
        for ($y = 0; $y < $sizey; $y++) {
            $color = imagecolorat($img_in, $x, $y);
            $allcolors[dechex($color)]++;
            $blue = 0xff & $color;
            $green = (0xff00 & $color) >> 8;
            $red = (0xff0000 & $color) >> 16;
            foreach ($transform as $line) {
                list($from, $to) = split("\t", $line);
                list($fr, $fg, $fb) = sscanf($from, '%2x%2x%2x');
                if ($blue == $fb and $red == $fr and $green == $fg) {
                    imagesetpixel($img_out, $x, $y, hexdec($to));
                }
            }
        }
    }
    ImagePNG($img_out, "out/{$outputfname}");
    imagedestroy($img_in);
    imagedestroy($img_out);
    print_r($allcolors);
}
function showphone()
{
    global $sx, $sy, $hdiv, $vdiv, $im, $v_phone;
    if ($v_phone) {
        ImageCopy($im, $v_phone, $sx - 5, $sy - 1, 0, 0, 14, 10);
    }
}
function ApplyMask(&$image, $mask)
{
    // Create copy of mask as mask may not be the same size as image
    $mask_resized = ImageCreateTrueColor(ImageSX($image), ImageSY($image));
    ImageCopyResampled($mask_resized, $mask, 0, 0, 0, 0, ImageSX($image), ImageSY($image), ImageSX($mask), ImageSY($mask));
    // Create working temp
    $mask_blendtemp = ImageCreateTrueColor(ImageSX($image), ImageSY($image));
    $color_background = ImageColorAllocate($mask_blendtemp, 0, 0, 0);
    ImageFilledRectangle($mask_blendtemp, 0, 0, ImageSX($mask_blendtemp), ImageSY($mask_blendtemp), $color_background);
    // switch off single color alph and switch on full alpha channel
    ImageAlphaBlending($mask_blendtemp, false);
    ImageSaveAlpha($mask_blendtemp, true);
    // loop the entire image and set pixels, this will be slow for large images
    for ($x = 0; $x < ImageSX($image); $x++) {
        for ($y = 0; $y < ImageSY($image); $y++) {
            $RealPixel = GetPixelColor($image, $x, $y);
            $MaskPixel = GrayscalePixel(GetPixelColor($mask_resized, $x, $y));
            $MaskAlpha = 127 - Floor($MaskPixel['red'] / 2) * (1 - $RealPixel['alpha'] / 127);
            $newcolor = ImageColorAllocateAlpha($mask_blendtemp, $RealPixel['red'], $RealPixel['green'], $RealPixel['blue'], $MaskAlpha);
            ImageSetPixel($mask_blendtemp, $x, $y, $newcolor);
        }
    }
    // don't need the mask copy anymore
    ImageDestroy($mask_resized);
    // switch off single color alph and switch on full alpha channel
    ImageAlphaBlending($image, false);
    ImageSaveAlpha($image, true);
    // replace the image with the blended temp
    ImageCopy($image, $mask_blendtemp, 0, 0, 0, 0, ImageSX($mask_blendtemp), ImageSY($mask_blendtemp));
    ImageDestroy($mask_blendtemp);
}
Example #5
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);
 }
Example #6
0
function bar_chart($question, $answers)
{
    // define colors to draw the bars
    $colors = array(0xff6600, 0x9900, 0x3333cc, 0xff0033, 0xffff00, 0x66ffff, 0x9900cc);
    $total = array_sum($answers['votes']);
    // define spacing values and other magic numbers
    $padding = 5;
    $line_width = 20;
    $scale = $line_width * 7.5;
    $bar_height = 10;
    $x = $y = $padding;
    // allocate a large palette for drawing, since you don't know
    // the image length ahead of time
    $image = ImageCreateTrueColor(150, 500);
    ImageFilledRectangle($image, 0, 0, 149, 499, 0xe0e0e0);
    $black = 0x0;
    // print the question
    $wrapped = explode("\n", wordwrap($question, $line_width));
    foreach ($wrapped as $line) {
        ImageString($image, 3, $x, $y, $line, $black);
        $y += 12;
    }
    $y += $padding;
    // print the answers
    for ($i = 0; $i < count($answers['answer']); $i++) {
        // format percentage
        $percent = sprintf('%1.1f', 100 * $answers['votes'][$i] / $total);
        $bar = sprintf('%d', $scale * $answers['votes'][$i] / $total);
        // grab color
        $c = $i % count($colors);
        // handle cases with more bars than colors
        $text_color = $colors[$c];
        // draw bar and percentage numbers
        ImageFilledRectangle($image, $x, $y, $x + $bar, $y + $bar_height, $text_color);
        ImageString($image, 3, $x + $bar + $padding, $y, "{$percent}%", $black);
        $y += 12;
        // print answer
        $wrapped = explode("\n", wordwrap($answers['answer'][$i], $line_width));
        foreach ($wrapped as $line) {
            ImageString($image, 2, $x, $y, $line, $black);
            $y += 12;
        }
        $y += 7;
    }
    // crop image by copying it
    $chart = ImageCreateTrueColor(150, $y);
    ImageCopy($chart, $image, 0, 0, 0, 0, 150, $y);
    // PHP 5.5+ supports
    // $chart = ImageCrop($image, array('x' => 0, 'y' => 0,
    //                                  'width' => 150, 'height' => $y));
    // deliver image
    header('Content-type: image/png');
    ImagePNG($chart);
    // clean up
    ImageDestroy($image);
    ImageDestroy($chart);
}
 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);
 }
Example #8
0
 private static function img_resizer($src, $quality, $w, $h, $saveas)
 {
     /* v2.5 with auto crop */
     $r = 1;
     $e = strtolower(substr($src, strrpos($src, ".") + 1, 3));
     if ($e == "jpg" || $e == "jpeg") {
         $OldImage = imagecreatefromjpeg($src) or $r = 0;
     } elseif ($e == "gif") {
         $OldImage = ImageCreateFromGif($src) or $r = 0;
     } elseif ($e == "bmp") {
         $OldImage = ImageCreateFromwbmp($src) or $r = 0;
     } elseif ($e == "png") {
         $OldImage = ImageCreateFromPng($src) or $r = 0;
     } else {
         _o("No es una imagen v&aacute;lida! (" . $e . ") -- " . $src);
         $r = 0;
     }
     if ($r) {
         list($width, $height) = getimagesize($src);
         // check if ratios match
         $_ratio = array($width / $height, $w / $h);
         if ($_ratio[0] != $_ratio[1]) {
             // crop image
             // find the right scale to use
             $_scale = min((double) ($width / $w), (double) ($height / $h));
             // coords to crop
             $cropX = (double) ($width - $_scale * $w);
             $cropY = (double) ($height - $_scale * $h);
             // cropped image size
             $cropW = (double) ($width - $cropX);
             $cropH = (double) ($height - $cropY);
             $crop = ImageCreateTrueColor($cropW, $cropH);
             // crop the middle part of the image to fit proportions
             ImageCopy($crop, $OldImage, 0, 0, (int) ($cropX / 2), (int) ($cropY / 2), $cropW, $cropH);
         }
         // do the thumbnail
         $NewThumb = ImageCreateTrueColor($w, $h);
         if (isset($crop)) {
             // been cropped
             ImageCopyResampled($NewThumb, $crop, 0, 0, 0, 0, $w, $h, $cropW, $cropH);
             ImageDestroy($crop);
         } else {
             // ratio match, regular resize
             ImageCopyResampled($NewThumb, $OldImage, 0, 0, 0, 0, $w, $h, $width, $height);
         }
         _ckdir($saveas);
         ImageJpeg($NewThumb, $saveas, $quality);
         ImageDestroy($NewThumb);
         ImageDestroy($OldImage);
     }
     return $r;
 }
Example #9
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;
     }
 }
Example #11
0
File: GD.php Project: joeymetal/v1
 /**
  * Adds a border of constant width around an image
  *
  * @param int $border_width Width of border to add
  * @author Peter Bowyer
  * @return bool TRUE
  * @access public
  */
 function addBorder($border_width, $color = '')
 {
     $this->new_x = $this->img_x + 2 * $border_width;
     $this->new_y = $this->img_y + 2 * $border_width;
     $new_img = $this->_createImage($new_x, $new_y, $this->true_color);
     $options = array('pencilColor', $color);
     $color = $this->_getColor('pencilColor', $options, array(0, 0, 0));
     if ($color) {
         if ($this->true_color) {
             $c = imagecolorresolve($this->imageHandle, $color[0], $color[1], $color[2]);
             imagefill($new_img, 0, 0, $c);
         } else {
             imagecolorset($new_img, imagecolorat($new_img, 0, 0), $color[0], $color[1], $color[2]);
         }
     }
     ImageCopy($new_img, $this->imageHandle, $border_width, $border_width, 0, 0, $this->img_x, $this->img_y);
     $this->imageHandle = $new_img;
     $this->resized = true;
     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;
                }
            }
        }
    }
}
Example #13
0
 /**
  * Applies the effect.
  */
 public function apply()
 {
     $amount = $this->_params['amount'];
     $radius = $this->_params['radius'];
     $threshold = $this->_params['threshold'];
     // Attempt to calibrate the parameters to Photoshop:
     $amount = min($amount, 500);
     $amount = $amount * 0.016;
     if ($amount == 0) {
         return true;
     }
     $radius = min($radius, 50);
     $radius = $radius * 2;
     $threshold = min($threshold, 255);
     $radius = abs(round($radius));
     // Only integers make sense.
     if ($radius == 0) {
         return true;
     }
     $img = $this->_image->_im;
     $w = ImageSX($img);
     $h = ImageSY($img);
     $imgCanvas = ImageCreateTrueColor($w, $h);
     $imgCanvas2 = ImageCreateTrueColor($w, $h);
     $imgBlur = ImageCreateTrueColor($w, $h);
     $imgBlur2 = ImageCreateTrueColor($w, $h);
     ImageCopy($imgCanvas, $img, 0, 0, 0, 0, $w, $h);
     ImageCopy($imgCanvas2, $img, 0, 0, 0, 0, $w, $h);
     // Gaussian blur matrix:
     //
     //  1   2   1
     //  2   4   2
     //  1   2   1
     //
     //////////////////////////////////////////////////
     // Move copies of the image around one pixel at the time and merge them
     // with weight according to the matrix. The same matrix is simply
     // repeated for higher radii.
     for ($i = 0; $i < $radius; $i++) {
         // up left
         ImageCopy($imgBlur, $imgCanvas, 0, 0, 1, 1, $w - 1, $h - 1);
         // down right
         ImageCopyMerge($imgBlur, $imgCanvas, 1, 1, 0, 0, $w, $h, 50);
         // down left
         ImageCopyMerge($imgBlur, $imgCanvas, 0, 1, 1, 0, $w - 1, $h, 33.33333);
         // up right
         ImageCopyMerge($imgBlur, $imgCanvas, 1, 0, 0, 1, $w, $h - 1, 25);
         // left
         ImageCopyMerge($imgBlur, $imgCanvas, 0, 0, 1, 0, $w - 1, $h, 33.33333);
         // right
         ImageCopyMerge($imgBlur, $imgCanvas, 1, 0, 0, 0, $w, $h, 25);
         // up
         ImageCopyMerge($imgBlur, $imgCanvas, 0, 0, 0, 1, $w, $h - 1, 20);
         // down
         ImageCopyMerge($imgBlur, $imgCanvas, 0, 1, 0, 0, $w, $h, 16.666667);
         // center
         ImageCopyMerge($imgBlur, $imgCanvas, 0, 0, 0, 0, $w, $h, 50);
         ImageCopy($imgCanvas, $imgBlur, 0, 0, 0, 0, $w, $h);
         // During the loop above the blurred copy darkens, possibly due to
         // a roundoff error. Therefore the sharp picture has to go through
         // the same loop to produce a similar image for comparison. This is
         // not a good thing, as processing time increases heavily.
         ImageCopy($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h);
         ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 50);
         ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 33.33333);
         ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 25);
         ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 33.33333);
         ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 25);
         ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 20);
         ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 16.666667);
         ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 50);
         ImageCopy($imgCanvas2, $imgBlur2, 0, 0, 0, 0, $w, $h);
     }
     // Calculate the difference between the blurred pixels and the original
     // and set the pixels
     for ($x = 0; $x < $w; $x++) {
         for ($y = 0; $y < $h; $y++) {
             $rgbOrig = ImageColorAt($imgCanvas2, $x, $y);
             $rOrig = $rgbOrig >> 16 & 0xff;
             $gOrig = $rgbOrig >> 8 & 0xff;
             $bOrig = $rgbOrig & 0xff;
             $rgbBlur = ImageColorAt($imgCanvas, $x, $y);
             $rBlur = $rgbBlur >> 16 & 0xff;
             $gBlur = $rgbBlur >> 8 & 0xff;
             $bBlur = $rgbBlur & 0xff;
             // When the masked pixels differ less from the original than
             // the threshold specifies, they are set to their original
             // value.
             $rNew = abs($rOrig - $rBlur) >= $threshold ? max(0, min(255, $amount * ($rOrig - $rBlur) + $rOrig)) : $rOrig;
             $gNew = abs($gOrig - $gBlur) >= $threshold ? max(0, min(255, $amount * ($gOrig - $gBlur) + $gOrig)) : $gOrig;
             $bNew = abs($bOrig - $bBlur) >= $threshold ? max(0, min(255, $amount * ($bOrig - $bBlur) + $bOrig)) : $bOrig;
             if ($rOrig != $rNew || $gOrig != $gNew || $bOrig != $bNew) {
                 $pixCol = ImageColorAllocate($img, $rNew, $gNew, $bNew);
                 ImageSetPixel($img, $x, $y, $pixCol);
             }
         }
     }
     ImageDestroy($imgCanvas);
     ImageDestroy($imgCanvas2);
     ImageDestroy($imgBlur);
     ImageDestroy($imgBlur2);
 }
 // Paint the image white
 ImageFill($imageOut, 0, 0, ImageColorAllocate($imageOut, 255, 255, 255));
 // Draw a border in destination image
 ImageRectangle($imageOut, 0, 0, $outX - 1, $outY - 1, ImageColorAllocate($imageOut, 0, 0, 0));
 // Do the work
 $nextX = BORDER_LEFT;
 $nextY = BORDER_TOP;
 foreach ($imageKeys as $imageKey) {
     // Fetch the image
     print "  Fetch image '{$imageKey}'\n";
     $image = $s3->get_object(BOOK_BUCKET, $imageKey);
     // Convert it to GD format
     $imageBits = ImageCreateFromString($image->body);
     // Copy it to proper spot in the destination
     print "  Render image at {$nextX}, {$nextY}\n";
     ImageCopy($imageOut, $imageBits, $nextX, $nextY, 0, 0, ImageSx($imageBits), ImageSy($imageBits));
     // Draw a border around it
     ImageRectangle($imageOut, $nextX, $nextY, $nextX + ImageSx($imageBits), $nextY + ImageSy($imageBits), ImageColorAllocate($imageOut, 0, 0, 0));
     // Update position for next image
     $nextX += THUMB_SIZE + GAP_SIZE;
     if ($nextX + THUMB_SIZE > $outX) {
         $nextX = BORDER_LEFT;
         $nextY += THUMB_SIZE + GAP_SIZE;
     }
 }
 // Get the bits of the destination image
 $imageFileOut = tempnam('/tmp', 'aws') . '.png';
 ImagePNG($imageOut, $imageFileOut, 0);
 $imageBitsOut = file_get_contents($imageFileOut);
 unlink($imageFileOut);
 // Store the final image in S3
Example #15
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;
     }
 }
 private static function resizeImage($path, $newpath, $nw = 0, $nh = 0, $quality = 90)
 {
     if (!$path || !$newpath) {
         return false;
     }
     if (!(list($w, $h, $type, $attr) = getimagesize($path))) {
         return false;
     }
     $OldImage = null;
     switch ($type) {
         case 1:
             $OldImage = imagecreatefromgif($path);
             break;
         case 2:
             $OldImage = imagecreatefromjpeg($path);
             break;
         case 3:
             $OldImage = imagecreatefrompng($path);
             break;
         default:
             return false;
             break;
     }
     if ($nw == 0 && $nh == 0) {
         $nw = 75;
         $nh = (int) floor($nw * $h / $w);
     } elseif ($nw == 0) {
         $nw = (int) floor($nh * $w / $h);
     } elseif ($nh == 0) {
         $nh = (int) floor($nw * $h / $w);
     }
     // check if ratios match
     $_ratio = array($w / $h, $nw / $nh);
     if ($_ratio[0] != $_ratio[1]) {
         // crop image
         // find the right scale to use
         $_scale = min((double) ($w / $nw), (double) ($h / $nh));
         // coords to crop
         $cropX = (double) ($w - $_scale * $nw);
         $cropY = (double) ($h - $_scale * $nh);
         // cropped image size
         $cropW = (double) ($w - $cropX);
         $cropH = (double) ($h - $cropY);
         $crop = ImageCreateTrueColor($cropW, $cropH);
         if ($type == 3) {
             imagecolortransparent($crop, imagecolorallocate($crop, 0, 0, 0));
             imagealphablending($crop, false);
             imagesavealpha($crop, true);
         }
         ImageCopy($crop, $OldImage, 0, 0, (int) ($cropX / 2), (int) ($cropY / 2), $cropW, $cropH);
     }
     // do the thumbnail
     $NewThumb = ImageCreateTrueColor($nw, $nh);
     if ($type == 3) {
         imagecolortransparent($NewThumb, imagecolorallocate($NewThumb, 0, 0, 0));
         imagealphablending($NewThumb, false);
         imagesavealpha($NewThumb, true);
     }
     if (isset($crop)) {
         // been cropped
         ImageCopyResampled($NewThumb, $crop, 0, 0, 0, 0, $nw, $nh, $cropW, $cropH);
         ImageDestroy($crop);
     } else {
         // ratio match, regular resize
         ImageCopyResampled($NewThumb, $OldImage, 0, 0, 0, 0, $nw, $nh, $w, $h);
     }
     if (is_file($newpath)) {
         unlink($newpath);
     }
     imageinterlace($NewThumb, 1);
     // progressive jpeg
     switch ($type) {
         case 1:
             imagegif($NewThumb, $newpath);
             break;
         case 2:
             imagejpeg($NewThumb, $newpath, $quality);
             break;
         case 3:
             imagepng($NewThumb, $newpath);
             break;
     }
     ImageDestroy($NewThumb);
     ImageDestroy($OldImage);
     return true;
 }
 static function imageCopy($imageObject, $destinationGeometry, $sourceGeometry, $sourceMimeData, $destinationMimeData)
 {
     $destinationWidth = $destinationGeometry['width'];
     $destinationHeight = $destinationGeometry['height'];
     $temporaryImageObject = eZImageGDHandler::imageCreate($destinationWidth, $destinationHeight, eZImageGDHandler::isImageTrueColor($imageObject, $sourceMimeData));
     ImageCopy($temporaryImageObject, $imageObject, $destinationGeometry['x'], $destinationGeometry['y'], $sourceGeometry['x'], $sourceGeometry['y'], $sourceGeometry['width'], $sourceGeometry['height']);
     return $temporaryImageObject;
 }
/**
* resize_image()
*
* Create a file containing a resized image
*
* @param  $src_file the source file
* @param  $dest_file the destination file
* @param  $new_size the size of the square within which the new image must fit
* @param  $method the method used for image resizing
* @return 'true' in case of success
*/
function resize_image($src_file, $dest_file, $new_size, $method, $thumb_use, $watermark = "false", $sharpen = 0, $media_type = "false")
{
    global $CONFIG, $ERROR;
    global $lang_errors;
    list($sharpen) = CPGPluginAPI::filter('image_sharpen', array($sharpen, $new_size));
    //Make Cage
    $superCage = Inspekt::makeSuperCage();
    $imginfo = cpg_getimagesize($src_file);
    if ($imginfo == null) {
        return false;
    }
    // GD can only handle JPG & PNG images
    if ($imginfo[2] != GIS_JPG && $imginfo[2] != GIS_PNG && $CONFIG['GIF_support'] == 0) {
        $ERROR = $lang_errors['gd_file_type_err'];
        //return false;
        return array('error' => $ERROR);
    }
    // height/width
    $srcWidth = $imginfo[0];
    $srcHeight = $imginfo[1];
    $crop = 0;
    // initialize
    // if cropping is enabled calculate cropping parameters
    if ($thumb_use == 'ex') {
        $thb_width = $CONFIG['thumb_width'];
        $thb_height = $CONFIG['thumb_height'];
        if ($new_size == $thb_width) {
            $crop = 1;
            switch ($CONFIG['thumb_method']) {
                //cropping parameters for ImageMagick
                case "im":
                    $resize_commands = "";
                    if ($srcWidth / $srcHeight > $thb_width / $thb_height) {
                        $resize_commands .= "-resize x" . $thb_height;
                        $resized_w = $thb_height / $srcHeight * $srcWidth;
                        $resize_commands .= " -crop " . $thb_width . "x" . $thb_height . "+" . round(($resized_w - $thb_width) / 2) . "+0";
                    } else {
                        $resize_commands .= "-resize " . $thb_width;
                        $resized_h = $thb_width / $srcWidth * $srcHeight;
                        $resize_commands .= " -crop " . $thb_width . "x" . $thb_height . "+0+" . round(($resized_h - $thb_height) / 2);
                    }
                    break;
                    // cropping parameters for GD2
                // cropping parameters for GD2
                default:
                    if ($srcHeight < $srcWidth) {
                        $ratio = (double) ($srcHeight / $thb_height);
                        $cpyWidth = round($thb_width * $ratio);
                        if ($cpyWidth > $srcWidth) {
                            $ratio = (double) ($srcWidth / $thb_width);
                            $cpyWidth = $srcWidth;
                            $cpyHeight = round($thb_height * $ratio);
                            $xOffset = 0;
                            $yOffset = round(($srcHeight - $cpyHeight) / 2);
                        } else {
                            $cpyHeight = $srcHeight;
                            $xOffset = round(($srcWidth - $cpyWidth) / 2);
                            $yOffset = 0;
                        }
                    } else {
                        $ratio = (double) ($srcWidth / $thb_width);
                        $cpyHeight = round($thb_height * $ratio);
                        if ($cpyHeight > $srcHeight) {
                            $ratio = (double) ($srcHeight / $thb_height);
                            $cpyHeight = $srcHeight;
                            $cpyWidth = round($thb_width * $ratio);
                            $xOffset = round(($srcWidth - $cpyWidth) / 2);
                            $yOffset = 0;
                        } else {
                            $cpyWidth = $srcWidth;
                            $xOffset = 0;
                            $yOffset = round(($srcHeight - $cpyHeight) / 2);
                        }
                    }
                    $destWidth = $thb_width;
                    $destHeight = $thb_height;
                    $srcWidth = $cpyWidth;
                    $srcHeight = $cpyHeight;
                    break;
            }
        } else {
            $ratio = max($srcWidth, $srcHeight) / $new_size;
        }
    } elseif ($thumb_use == 'wd') {
        // resize method width
        $ratio = $srcWidth / $new_size;
    } elseif ($thumb_use == 'ht') {
        // resize method height
        $ratio = $srcHeight / $new_size;
    } else {
        // resize method any
        $ratio = max($srcWidth, $srcHeight) / $new_size;
    }
    $ratio = max($ratio, 1.0);
    if ($thumb_use == 'orig') {
        $ratio = 1.0;
    }
    if ($crop != 1) {
        $destWidth = (int) ($srcWidth / $ratio);
        $destHeight = (int) ($srcHeight / $ratio);
        $resize_commands = "-geometry " . $destWidth . "x" . $destHeight;
        $xOffset = 0;
        $yOffset = 0;
    }
    // Method for thumbnails creation
    switch ($method) {
        case "im":
            if (preg_match("#[A-Z]:|\\\\#Ai", __FILE__)) {
                // get the basedir, remove '/include'
                $cur_dir = substr(dirname(__FILE__), 0, -8);
                $src_file = '"' . $cur_dir . '\\' . strtr($src_file, '/', '\\') . '"';
                $im_dest_file = str_replace('%', '%%', '"' . $cur_dir . '\\' . strtr($dest_file, '/', '\\') . '"');
            } else {
                $src_file = escapeshellarg($src_file);
                $im_dest_file = str_replace('%', '%%', escapeshellarg($dest_file));
            }
            $output = array();
            /*
             * Hack for working with ImageMagick on Windows even if IM is installed in C:\Program Files.
             * By Aditya Mooley <*****@*****.**>
             */
            if ($sharpen == 1 && $CONFIG['enable_unsharp'] == 1) {
                $unsharp_mask = " -unsharp " . $CONFIG['unsharp_radius'] . "x" . sqrt($CONFIG['unsharp_radius']) . "+" . $CONFIG['unsharp_amount'] / 100 . "+" . $CONFIG['unsharp_threshold'] / 100 . " ";
            } else {
                $unsharp_mask = "";
            }
            if ($superCage->env->getMatched('OS', '/win/i')) {
                $cmd = "\"" . str_replace("\\", "/", $CONFIG['impath']) . "convert\" -quality {$CONFIG['jpeg_qual']} {$CONFIG['im_options']} " . $resize_commands . " " . $unsharp_mask . " " . str_replace("\\", "/", $src_file) . " " . str_replace("\\", "/", $im_dest_file);
                exec("\"{$cmd}\"", $output, $retval);
            } else {
                $cmd = "{$CONFIG['impath']}convert -quality {$CONFIG['jpeg_qual']} {$CONFIG['im_options']} " . $resize_commands . " " . $unsharp_mask . " {$src_file} {$im_dest_file}";
                exec($cmd, $output, $retval);
            }
            if ($media_type != "false") {
                //if a manual thumb gets generated we watermark the thumb with the media type
                //we now need to get the absolute path to the thumb watermark files
                $path_parts = pathinfo($CONFIG['watermark_file']);
                $CONFIG['watermark_file'] = $path_parts["dirname"] . "/wm_" . $media_type . ".png";
            }
            if ($watermark == "true" || $media_type != "false") {
                //do we need to resize the watermark to fit onto the intermediate?
                $wm_normal = (int) $CONFIG['reduce_watermark'];
                if ($wm_normal > $destWidth) {
                    $wm_resize = (int) ($destWidth / $wm_normal * 100);
                    //we have to create a temporary, downsized watermark file in the edit folder
                    //temp path for small wm
                    $path_to_tmp_wm = './' . $CONFIG['fullpath'] . 'edit/temp_wm.png';
                    if ($superCage->env->getMatched('OS', '/win/i')) {
                        $cmd = "\"" . str_replace("\\", "/", $CONFIG['impath']) . "convert\" -resize " . $wm_resize . "% " . str_replace("\\", "/", $CONFIG['watermark_file']) . " " . str_replace("\\", "/", $path_to_tmp_wm);
                        exec("\"{$cmd}\"", $output, $retval);
                    } else {
                        $cmd = "{$CONFIG['impath']}convert -resize {$wm_resize}% {$CONFIG['watermark_file']} {$path_to_tmp_wm}";
                        exec($cmd, $output, $retval);
                    }
                    $wm_file = $path_to_tmp_wm;
                    //set the path to the wm file to the temp one
                } else {
                    $wm_file = $CONFIG['watermark_file'];
                    //if no downsize... we take the orig watermark
                }
                // now we apply the watermark
                if ($superCage->env->getMatched('OS', '/win/i')) {
                    $cmd = "\"" . str_replace("\\", "/", $CONFIG['impath']) . "composite\" -dissolve {$CONFIG['watermark_transparency']} -gravity {$CONFIG['where_put_watermark']} \"{$wm_file}\" " . str_replace("\\", "/", $im_dest_file) . " " . str_replace("\\", "/", $im_dest_file);
                    exec("\"{$cmd}\"", $output, $retval);
                } else {
                    $cmd = "{$CONFIG['impath']}composite -dissolve {$CONFIG['watermark_transparency']} -gravity {$CONFIG['where_put_watermark']} {$wm_file} {$im_dest_file} {$im_dest_file}";
                    exec($cmd, $output, $retval);
                }
            }
            if ($retval) {
                $ERROR = "Error executing ImageMagick - Return value: {$retval}";
                if ($CONFIG['debug_mode']) {
                    // Re-execute the command with the backtick operator in order to get all outputs
                    // will not work is safe mode is enabled
                    $output = `{$cmd} 2>&1`;
                    $ERROR .= "<br /><br /><div align=\"left\">Cmd line : <br /><span style=\"font-size:120%\">" . nl2br(htmlspecialchars($cmd)) . "</span></div>";
                    $ERROR .= "<br /><br /><div align=\"left\">The convert program said:<br /><span style=\"font-size:120%\">";
                    $ERROR .= nl2br(htmlspecialchars($output));
                    $ERROR .= "</span></div>";
                }
                @unlink($dest_file);
                return array('error' => $ERROR);
            }
            break;
        case "gd1":
            if (!function_exists('imagecreatefromjpeg')) {
                return array('error' => 'PHP running on your server does not support the GD image library, check with your webhost if ImageMagick is installed', 'halt_upload' => 1);
            }
            if ($imginfo[2] == GIS_JPG) {
                $src_img = imagecreatefromjpeg($src_file);
            } else {
                $src_img = imagecreatefrompng($src_file);
            }
            if (!$src_img) {
                $ERROR = $lang_errors['invalid_image'];
                return array('error' => $ERROR);
            }
            $dst_img = imagecreate($destWidth, $destHeight);
            imagecopyresized($dst_img, $src_img, 0, 0, $xOffset, $yOffset, (int) $destWidth, (int) $destHeight, $srcWidth, $srcHeight);
            touch($dest_file);
            $fh = fopen($dest_file, 'w');
            fclose($fh);
            imagejpeg($dst_img, $dest_file, $CONFIG['jpeg_qual']);
            imagedestroy($src_img);
            imagedestroy($dst_img);
            break;
        case "gd2":
            if (!function_exists('imagecreatefromjpeg')) {
                return array('error' => 'PHP running on your server does not support the GD image library, check with your webhost if ImageMagick is installed', 'halt_upload' => 1);
            }
            if (!function_exists('imagecreatetruecolor')) {
                return array('error' => 'PHP running on your server does not support GD version 2.x, please switch to GD version 1.x on the admin page', 'halt_upload' => 1);
            }
            if ($imginfo[2] == GIS_GIF && $CONFIG['GIF_support'] == 1) {
                $src_img = imagecreatefromgif($src_file);
            } elseif ($imginfo[2] == GIS_JPG) {
                $src_img = imagecreatefromjpeg($src_file);
            } else {
                $src_img = imagecreatefrompng($src_file);
            }
            if (!$src_img) {
                $ERROR = $lang_errors['invalid_image'];
                //return false;
                return array('error' => $ERROR);
            }
            if ($imginfo[2] == GIS_GIF) {
                $dst_img = imagecreate($destWidth, $destHeight);
            } else {
                $dst_img = imagecreatetruecolor($destWidth, $destHeight);
                if ($imginfo[2] == GIS_PNG) {
                    imagealphablending($dst_img, false);
                }
            }
            imagecopyresampled($dst_img, $src_img, 0, 0, $xOffset, $yOffset, (int) $destWidth, (int) $destHeight, $srcWidth, $srcHeight);
            touch($dest_file);
            $fh = fopen($dest_file, 'w');
            fclose($fh);
            //sharpen the thumb
            if ($sharpen == 1 && $CONFIG['enable_unsharp'] == 1) {
                UnsharpMask($dst_img, $CONFIG['unsharp_amount'], $CONFIG['unsharp_radius'], $CONFIG['unsharp_threshold']);
            }
            if ($media_type != "false") {
                //if a manual thumb gets generated we watermark the thumb with the media type
                //we now need to get the absolute path to the thumb watermark files
                $path_parts = pathinfo($CONFIG['watermark_file']);
                $CONFIG['watermark_file'] = $path_parts["dirname"] . "/wm_" . $media_type . ".png";
            }
            if ($watermark == "true" || $media_type != "false") {
                //shrink watermark on intermediate images -> If I had known that this is that �%&# with the transparency preserve... grrr
                $wm_normal = (int) $CONFIG['reduce_watermark'];
                if ($wm_normal > $destWidth) {
                    $wm_resize = $destWidth / $wm_normal;
                    //load the original, huge sized logo (the one we want to size down)
                    $temp_logoImage = ImageCreateFromPNG($CONFIG['watermark_file']);
                    //get it's size
                    $temp_logoW = ImageSX($temp_logoImage);
                    $temp_logoH = ImageSY($temp_logoImage);
                    //calculate new size
                    $logoW = (int) ($temp_logoW * $wm_resize);
                    $logoH = (int) ($temp_logoH * $wm_resize);
                    //we create a new, resized logo
                    $logoImage = imagecreatetruecolor($logoW, $logoH);
                    //just to be sure that transparency gets preserved
                    imagealphablending($logoImage, FALSE);
                    imagealphablending($temp_logoImage, TRUE);
                    //now copy and resize the big one into the temp resized img
                    imagecopyresampled($logoImage, $temp_logoImage, 0, 0, 0, 0, (int) $logoW, (int) $logoH, $temp_logoW, $temp_logoH);
                    //we do not need the temp (huge) watermark anymore
                    imagedestroy($temp_logoImage);
                } else {
                    // shrink not enabled or no intermediate...
                    $logoImage = ImageCreateFromPNG($CONFIG['watermark_file']);
                    $logoW = ImageSX($logoImage);
                    $logoH = ImageSY($logoImage);
                }
                //where is the watermark displayed...
                $pos = $CONFIG['where_put_watermark'];
                if ($pos == "northwest") {
                    $src_x = 5;
                    $src_y = 5;
                } else {
                    if ($pos == "northeast") {
                        $src_x = $destWidth - ($logoW + 5);
                        $src_y = 5;
                    } else {
                        if ($pos == "southwest") {
                            $src_x = 5;
                            $src_y = $destHeight - ($logoH + 5);
                        } else {
                            if ($pos == "southeast") {
                                $src_x = $destWidth - ($logoW + 5);
                                $src_y = $destHeight - ($logoH + 5);
                            } else {
                                if ($pos == "center") {
                                    $src_x = $destWidth / 2 - $logoW / 2;
                                    $src_y = $destHeight / 2 - $logoH / 2;
                                }
                            }
                        }
                    }
                }
                imagealphablending($dst_img, TRUE);
                imagecolortransparent($logoImage, imagecolorat($logoImage, $CONFIG['watermark_transparency_featherx'], $CONFIG['watermark_transparency_feathery']));
                ImageCopy($dst_img, $logoImage, $src_x, $src_y, 0, 0, $logoW, $logoH);
            }
            if ($imginfo[2] == GIS_PNG) {
                imagesavealpha($dst_img, true);
                imagepng($dst_img, $dest_file, round((100 - $CONFIG['jpeg_qual']) / 10));
            } else {
                imagejpeg($dst_img, $dest_file, $CONFIG['jpeg_qual']);
            }
            imagedestroy($src_img);
            imagedestroy($dst_img);
            break;
    }
    // Set mode of uploaded picture
    @chmod($dest_file, octdec($CONFIG['default_file_mode']));
    //silence the output in case chmod is disabled
    // We check that the image is valid
    $imginfo = cpg_getimagesize($dest_file);
    if ($imginfo == null) {
        $ERROR = $lang_errors['resize_failed'];
        @unlink($dest_file);
        //return false;
        return array('error' => $ERROR);
    } else {
        return true;
    }
}
Example #19
0
 /**
  * Performs the actual cropping of the image
  * 
  * @since 2.0
  * @param integer $leftOffset Number of pixels from the left side of the image to crop in
  * @param integer $topOffset Number of pixels from the top side of the image to crop in
  * @param boolean $isBackgroundFillOn
  * @return boolean
  */
 private function cropImage($leftOffset, $topOffset, $isBackgroundFillOn)
 {
     // Set up a blank canvas for our cropped image (destination)
     $cropped = imagecreatetruecolor($this->cropWidth, $this->cropHeight);
     $this->background($isBackgroundFillOn, $cropped);
     // Copy rendered image to cropped image
     ImageCopy($cropped, $this->image, 0, 0, $leftOffset, $topOffset, $this->width, $this->height);
     // Replace pre-cropped image with cropped image
     imagedestroy($this->image);
     $this->image = $cropped;
     unset($cropped);
     return TRUE;
 }
Example #20
0
 public function cropOrResizeImage($image, $quality, $currWidth, $currHeight, $finalWidth, $finalHeight, $fianlImageDest)
 {
     if ($image) {
         // check if ratios match
         $_ratio = array($currWidth / $currHeight, $finalWidth / $finalHeight);
         if ($_ratio[0] != $_ratio[1]) {
             // crop image
             // find the right scale to use
             $_scale = min((double) ($currWidth / $finalWidth), (double) ($currHeight / $finalHeight));
             // coords to crop
             $cropX = (double) ($currWidth - $_scale * $finalWidth);
             $cropY = (double) ($currHeight - $_scale * $finalHeight);
             // cropped image size
             $cropW = (double) ($currWidth - $cropX);
             $cropH = (double) ($currHeight - $cropY);
             $crop = ImageCreateTrueColor($cropW, $cropH);
             // crop the middle part of the image to fit proportions
             ImageCopy($crop, $image, 0, 0, (int) ($cropX / 2), (int) ($cropY / 2), $cropW, $cropH);
         }
         // do the thumbnail
         $newThumb = ImageCreateTrueColor($finalWidth, $finalHeight);
         if (isset($crop)) {
             // been cropped
             ImageCopyResampled($newThumb, $crop, 0, 0, 0, 0, $finalWidth, $finalHeight, $cropW, $cropH);
             ImageDestroy($crop);
         } else {
             // ratio match, regular resize
             ImageCopyResampled($newThumb, $image, 0, 0, 0, 0, $finalWidth, $finalHeight, $currWidth, $currHeight);
         }
         ImageJpeg($newThumb, $fianlImageDest, $quality);
         ImageDestroy($newThumb);
         ImageDestroy($image);
         return true;
     }
     return;
 }
 function blendImage($destinationImageObject, $imageObject, $destinationX, $destinationY, $sourceWidth, $sourceHeight, $sourceX = 0, $sourceY = 0)
 {
     ImageAlphaBlending($destinationImageObject, true);
     ImageCopy($destinationImageObject, $imageObject, $destinationX, $destinationY, $sourceX, $sourceY, $sourceWidth, $sourceHeight);
 }
Example #22
0
 function ImageResizeFunction(&$dst_im, &$src_im, $dstX, $dstY, $srcX, $srcY, $dstW, $dstH, $srcW, $srcH)
 {
     $this->DebugMessage('ImageResizeFunction($o, $s, ' . $dstX . ', ' . $dstY . ', ' . $srcX . ', ' . $srcY . ', ' . $dstW . ', ' . $dstH . ', ' . $srcW . ', ' . $srcH . ')', __FILE__, __LINE__);
     if ($dstW == $srcW && $dstH == $srcH) {
         return ImageCopy($dst_im, $src_im, $dstX, $dstY, $srcX, $srcY, $srcW, $srcH);
     }
     if (phpthumb_functions::gd_version() >= 2.0) {
         if ($this->config_disable_imagecopyresampled) {
             return phpthumb_functions::ImageCopyResampleBicubic($dst_im, $src_im, $dstX, $dstY, $srcX, $srcY, $dstW, $dstH, $srcW, $srcH);
         }
         return ImageCopyResampled($dst_im, $src_im, $dstX, $dstY, $srcX, $srcY, $dstW, $dstH, $srcW, $srcH);
     }
     return ImageCopyResized($dst_im, $src_im, $dstX, $dstY, $srcX, $srcY, $dstW, $dstH, $srcW, $srcH);
 }
 function applyUnsharpMask(&$img, $amount, $radius, $threshold)
 {
     // $img is an image that is already created within php using
     // imgcreatetruecolor. No url! $img must be a truecolor image.
     // Attempt to calibrate the parameters to Photoshop:
     $amount = min($amount, 500);
     $amount = $amount * 0.016;
     if ($amount == 0) {
         return true;
     }
     $radius = min($radius, 50);
     $radius = $radius * 2;
     $threshold = min($threshold, 255);
     $radius = abs(round($radius));
     // Only integers make sense.
     if ($radius == 0) {
         return true;
     }
     $w = ImageSX($img);
     $h = ImageSY($img);
     $imgCanvas = ImageCreateTrueColor($w, $h);
     $imgCanvas2 = ImageCreateTrueColor($w, $h);
     ImageCopy($imgCanvas, $img, 0, 0, 0, 0, $w, $h);
     ImageCopy($imgCanvas2, $img, 0, 0, 0, 0, $w, $h);
     $builtinFilterSucceeded = false;
     if ($radius == 1) {
         if (phpthumb_functions::version_compare_replacement(phpversion(), '5.0.0', '>=') && phpthumb_functions::gd_is_bundled()) {
             if (ImageFilter($imgCanvas, IMG_FILTER_GAUSSIAN_BLUR) && ImageFilter($imgCanvas2, IMG_FILTER_GAUSSIAN_BLUR)) {
                 $builtinFilterSucceeded = true;
             }
         }
     }
     if (!$builtinFilterSucceeded) {
         $imgBlur = ImageCreateTrueColor($w, $h);
         $imgBlur2 = ImageCreateTrueColor($w, $h);
         ///////////////////////////
         //
         // Gaussian blur matrix:
         //	1  2  1
         //	2  4  2
         //	1  2  1
         //
         ///////////////////////////
         // Move copies of the image around one pixel at the time and merge them with weight
         // according to the matrix. The same matrix is simply repeated for higher radii.
         for ($i = 0; $i < $radius; $i++) {
             ImageCopy($imgBlur, $imgCanvas, 0, 0, 1, 1, $w - 1, $h - 1);
             // up left
             ImageCopyMerge($imgBlur, $imgCanvas, 1, 1, 0, 0, $w, $h, 50);
             // down right
             ImageCopyMerge($imgBlur, $imgCanvas, 0, 1, 1, 0, $w - 1, $h, 33.33333);
             // down left
             ImageCopyMerge($imgBlur, $imgCanvas, 1, 0, 0, 1, $w, $h - 1, 25);
             // up right
             ImageCopyMerge($imgBlur, $imgCanvas, 0, 0, 1, 0, $w - 1, $h, 33.33333);
             // left
             ImageCopyMerge($imgBlur, $imgCanvas, 1, 0, 0, 0, $w, $h, 25);
             // right
             ImageCopyMerge($imgBlur, $imgCanvas, 0, 0, 0, 1, $w, $h - 1, 20);
             // up
             ImageCopyMerge($imgBlur, $imgCanvas, 0, 1, 0, 0, $w, $h, 16.666667);
             // down
             ImageCopyMerge($imgBlur, $imgCanvas, 0, 0, 0, 0, $w, $h, 50);
             // center
             ImageCopy($imgCanvas, $imgBlur, 0, 0, 0, 0, $w, $h);
             // During the loop above the blurred copy darkens, possibly due to a roundoff
             // error. Therefore the sharp picture has to go through the same loop to
             // produce a similar image for comparison. This is not a good thing, as processing
             // time increases heavily.
             ImageCopy($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h);
             ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 50);
             ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 33.33333);
             ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 25);
             ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 33.33333);
             ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 25);
             ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 20);
             ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 16.666667);
             ImageCopyMerge($imgBlur2, $imgCanvas2, 0, 0, 0, 0, $w, $h, 50);
             ImageCopy($imgCanvas2, $imgBlur2, 0, 0, 0, 0, $w, $h);
         }
         ImageDestroy($imgBlur);
         ImageDestroy($imgBlur2);
     }
     // Calculate the difference between the blurred pixels and the original
     // and set the pixels
     for ($x = 0; $x < $w; $x++) {
         // each row
         for ($y = 0; $y < $h; $y++) {
             // each pixel
             $rgbOrig = ImageColorAt($imgCanvas2, $x, $y);
             $rOrig = $rgbOrig >> 16 & 0xff;
             $gOrig = $rgbOrig >> 8 & 0xff;
             $bOrig = $rgbOrig & 0xff;
             $rgbBlur = ImageColorAt($imgCanvas, $x, $y);
             $rBlur = $rgbBlur >> 16 & 0xff;
             $gBlur = $rgbBlur >> 8 & 0xff;
             $bBlur = $rgbBlur & 0xff;
             // When the masked pixels differ less from the original
             // than the threshold specifies, they are set to their original value.
             $rNew = abs($rOrig - $rBlur) >= $threshold ? max(0, min(255, $amount * ($rOrig - $rBlur) + $rOrig)) : $rOrig;
             $gNew = abs($gOrig - $gBlur) >= $threshold ? max(0, min(255, $amount * ($gOrig - $gBlur) + $gOrig)) : $gOrig;
             $bNew = abs($bOrig - $bBlur) >= $threshold ? max(0, min(255, $amount * ($bOrig - $bBlur) + $bOrig)) : $bOrig;
             if ($rOrig != $rNew || $gOrig != $gNew || $bOrig != $bNew) {
                 $pixCol = ImageColorAllocate($img, $rNew, $gNew, $bNew);
                 ImageSetPixel($img, $x, $y, $pixCol);
             }
         }
     }
     ImageDestroy($imgCanvas);
     ImageDestroy($imgCanvas2);
     return true;
 }
Example #24
0
        $white = ImageColorAllocate($temp_im, 255, 255, 255);
        ImageFill($temp_im, 0, 0, $white);
        ImageCopyMerge($im3, $temp_im, 0, 0, 0, 0, $width, $height, $bg_fade_pct);
        // for debug:
        //sendImage($im3);
        ImageDestroy($temp_im);
        $c_fade_pct = 50;
    } else {
        $c_fade_pct = $bg_fade_pct;
    }
    // captcha over bg:
    // might want to not blur if using this method
    // otherwise leaves white-ish border around each letter
    if ($merge_type == 1) {
        ImageCopyMerge($im3, $im, 0, 0, 0, 0, $width, $height, 100);
        ImageCopy($im, $im3, 0, 0, 0, 0, $width, $height);
    } else {
        // bg over captcha:
        ImageCopyMerge($im, $im3, 0, 0, 0, 0, $width, $height, $c_fade_pct);
    }
}
// for debug:
//sendImage($im);
//////////////////////////////////////////////////////
////// Write tags, remove variables and output!
//////////////////////////////////////////////////////
// tag it
// feel free to remove/change
// but if it's not essential I'd appreciate you leaving it
// after all, I've put a lot of work into this and am giving it away for free
// the least you could do is give me credit (or buy me stuff from amazon!)
Example #25
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;
 }
Example #26
0
 /**
  * need GD library (first PHP line WIN: dl("php_gd.dll"); UNIX: dl("gd.so");
  * www.boutell.com/gd/
  * interval.cz/clanky/php-skript-pro-generovani-galerie-obrazku-2/
  * cz.php.net/imagecopyresampled
  * www.linuxsoft.cz/sw_detail.php?id_item=871
  * www.webtip.cz/art/wt_tech_php/liquid_ir.html
  * php.vrana.cz/zmensovani-obrazku.php
  * diskuse.jakpsatweb.cz/
  *
  * @param string $file_in Vstupni soubor (mel by existovat)
  * @param string $file_out Vystupni soubor, null ho jenom zobrazi (taky kdyz nema pravo se zapsat :)
  * @param int $width Vysledna sirka (maximalni)
  * @param int $height Vysledna vyska (maximalni)
  * @param bool $crop Orez (true, obrazek bude presne tak velky), jinak jenom Resample (udane maximalni rozmery)
  * @param int $type_out IMAGETYPE_type vystupniho obrazku
  * @return bool Chyba kdyz vrati false
  */
 function imageMagic($file_in, $file_out = null, $width = null, $height = null, $crop = null, $type_out = null, $watermarkParams = array(), $frontUpload = 0)
 {
     $fileWatermark = '';
     // While front upload we don't display the process page
     if ($frontUpload == 0) {
         $stopText = PhocaGalleryHelper::displayStopThumbnailsCreating();
         echo $stopText;
     }
     $memory = 8;
     $memoryLimitChanged = 0;
     $memory = (int) ini_get('memory_limit');
     if ($memory == 0) {
         $memory = 8;
     }
     if ($file_in !== '' && file_exists($file_in)) {
         //array of width, height, IMAGETYPE, "height=x width=x" (string)
         list($w, $h, $type) = GetImageSize($file_in);
         if ($w > 0 && $h > 0) {
             // we got the info from GetImageSize
             // size of the image
             if ($width == null || $width == 0) {
                 // no width added
                 $width = $w;
             } else {
                 if ($height == null || $height == 0) {
                     // no height, adding the same as width
                     $height = $width;
                 }
             }
             if ($height == null || $height == 0) {
                 // no height, no width
                 $height = $h;
             }
             // miniaturizing
             if (!$crop) {
                 // new size - nw, nh (new width/height)
                 $scale = $width / $w < $height / $h ? $width / $w : $height / $h;
                 // smaller rate
                 $src = array(0, 0, $w, $h);
                 $dst = array(0, 0, floor($w * $scale), floor($h * $scale));
             } else {
                 // will be cropped
                 $scale = $width / $w > $height / $h ? $width / $w : $height / $h;
                 // greater rate
                 $newW = $width / $scale;
                 // check the size of in file
                 $newH = $height / $scale;
                 // which side is larger (rounding error)
                 if ($w - $newW > $h - $newH) {
                     $src = array(floor(($w - $newW) / 2), 0, floor($newW), $h);
                 } else {
                     $src = array(0, floor(($h - $newH) / 2), $w, floor($newH));
                 }
                 $dst = array(0, 0, floor($width), floor($height));
             }
             // Watermark
             if (!empty($watermarkParams) && $watermarkParams['create'] == 1) {
                 $thumbnailSmall = false;
                 $thumbnailMedium = false;
                 $thumbnailLarge = false;
                 $thumbnailMedium = preg_match("/phoca_thumb_m_/i", $file_out);
                 $thumbnailLarge = preg_match("/phoca_thumb_l_/i", $file_out);
                 $fileName = PhocaGalleryHelper::getTitleFromFilenameWithExt($file_in);
                 // Which Watermark will be used
                 if ($thumbnailMedium) {
                     $fileWatermark = str_replace($fileName, 'watermark-medium.png', $file_in);
                 } else {
                     if ($thumbnailLarge) {
                         $fileWatermark = str_replace($fileName, 'watermark-large.png', $file_in);
                     } else {
                         $fileWatermark = '';
                     }
                 }
                 if (!file_exists($fileWatermark)) {
                     $fileWatermark = '';
                 }
                 if ($fileWatermark != '') {
                     list($wW, $hW, $typeW) = GetImageSize($fileWatermark);
                     switch ($watermarkParams['x']) {
                         case 'left':
                             $locationX = 0;
                             break;
                         case 'right':
                             $locationX = $dst[2] - $wW;
                             break;
                         case 'center':
                         default:
                             $locationX = $dst[2] / 2 - $wW / 2;
                             break;
                     }
                     switch ($watermarkParams['y']) {
                         case 'top':
                             $locationY = 0;
                             break;
                         case 'bottom':
                             $locationY = $dst[3] - $hW;
                             break;
                         case 'middle':
                         default:
                             $locationY = $dst[3] / 2 - $hW / 2;
                             break;
                     }
                 }
             } else {
                 $fileWatermark = '';
             }
         }
         if ($memory < 50) {
             ini_set('memory_limit', '50M');
             $memoryLimitChanged = 1;
         }
         // Resampling
         // in file
         // Watemark
         if ($fileWatermark != '') {
             if (!function_exists('ImageCreateFromPNG')) {
                 return 'ErrorNoPNGFunction';
             }
             $waterImage1 = ImageCreateFromPNG($fileWatermark);
         }
         // End Watermark
         switch ($type) {
             case IMAGETYPE_JPEG:
                 if (!function_exists('ImageCreateFromJPEG')) {
                     return 'ErrorNoJPGFunction';
                 }
                 $image1 = ImageCreateFromJPEG($file_in);
                 break;
             case IMAGETYPE_PNG:
                 if (!function_exists('ImageCreateFromPNG')) {
                     return 'ErrorNoPNGFunction';
                 }
                 $image1 = ImageCreateFromPNG($file_in);
                 break;
             case IMAGETYPE_GIF:
                 if (!function_exists('ImageCreateFromGIF')) {
                     return 'ErrorNoGIFFunction';
                 }
                 $image1 = ImageCreateFromGIF($file_in);
                 break;
             case IMAGETYPE_WBMP:
                 if (!function_exists('ImageCreateFromWBMP')) {
                     return 'ErrorNoWBMPFunction';
                 }
                 $image1 = ImageCreateFromWBMP($file_in);
                 break;
             default:
                 return 'ErrorNotSupportedImage';
                 break;
         }
         if ($image1) {
             // protection against invalid image dimensions
             /*foreach ($dst as $kdst =>$vdst) {
             			if ($dst[$kdst] == 0 ) {
             			$dst[$kdst] = 1;
             			}
             		} */
             $image2 = @ImageCreateTruecolor($dst[2], $dst[3]);
             if (!$image2) {
                 return 'ErrorNoImageCreateTruecolor';
             }
             switch ($type) {
                 case IMAGETYPE_PNG:
                     //imagealphablending($image1, false);
                     @imagealphablending($image2, false);
                     //imagesavealpha($image1, true);
                     @imagesavealpha($image2, true);
                     break;
             }
             ImageCopyResampled($image2, $image1, $dst[0], $dst[1], $src[0], $src[1], $dst[2], $dst[3], $src[2], $src[3]);
             // Watermark
             if ($fileWatermark != '') {
                 ImageCopy($image2, $waterImage1, $locationX, $locationY, 0, 0, $wW, $hW);
             }
             // End Watermark
             // display the image
             if ($file_out == null) {
                 header("Content-type: " . image_type_to_mime_type($type_out));
             }
             // out file
             if ($type_out == null) {
                 // no bitmap
                 $type_out = $type == IMAGETYPE_WBMP ? IMAGETYPE_PNG : $type;
             }
             switch ($type_out) {
                 case IMAGETYPE_JPEG:
                     if (!function_exists('ImageJPEG')) {
                         return 'ErrorNoJPGFunction';
                     }
                     if (!@ImageJPEG($image2, $file_out, 85)) {
                         return 'ErrorWriteFile';
                     }
                     break;
                 case IMAGETYPE_PNG:
                     if (!function_exists('ImagePNG')) {
                         return 'ErrorNoPNGFunction';
                     }
                     if (!@ImagePNG($image2, $file_out)) {
                         return 'ErrorWriteFile';
                     }
                     break;
                 case IMAGETYPE_GIF:
                     if (!function_exists('ImageGIF')) {
                         return 'ErrorNoGIFFunction';
                     }
                     if (!@ImageGIF($image2, $file_out)) {
                         return 'ErrorWriteFile';
                     }
                     break;
                 default:
                     return 'ErrorNotSupportedImage';
                     break;
             }
             // free memory
             ImageDestroy($image1);
             ImageDestroy($image2);
             if (isset($waterImage1)) {
                 ImageDestroy($waterImage1);
             }
             if ($memoryLimitChanged == 1) {
                 $memoryString = $memory . 'M';
                 ini_set('memory_limit', $memoryString);
             }
             return 'Success';
             // Success
         } else {
             return 'Error1';
         }
         if ($memoryLimitChanged == 1) {
             $memoryString = $memory . 'M';
             ini_set('memory_limit', $memoryString);
         }
     }
     return 'Error2';
 }
    $background = imagecolorallocate($im_base, $backR, $backG, $backB);
} else {
    $background = imagecolorallocatealpha($im_base, 254, 0, 0, 127);
}
imagefill($im_base, 0, 0, $background);
imagealphablending($im_base, false);
// turn off the alpha blending to keep the alpha channel
imagesavealpha($im_base, true);
//add symbols to base
foreach ($bases as $num => $base) {
    $image = "im{$num}";
    $W = ImageSX(${$image});
    $H = ImageSY(${$image});
    $X = $xs[$num];
    $Y = $ys[$num];
    ImageCopy($im_base, ${$image}, $X - $xMin, $Y - $yMin, 0, 0, $W, $H);
    ImageDestroy(${$image});
}
/**
 * Step 4: ugly hack for transparent fills
 */
if ($trans_fill) {
    for ($x = 0; $x < $xMax - $xMin; $x++) {
        for ($y = 0; $y < $yMax - $yMin; $y++) {
            $rgb = imagecolorat($im_base, $x, $y);
            $r = $rgb >> 16;
            $g = $rgb >> 8 & 255;
            $b = $rgb & 255;
            if ($r == $rf and $g == $gf and $b == $bf) {
                imagesetpixel($im_base, $x, $y, $background);
            }
Example #28
0
# Print admit nr vertically
if ($ttf_ok) {
    ImageTTFText($im, 10, 0, $leftmargin + 210, $topm - 1, $black, $arial, $full_en);
    ImageTTFText($im, 11, 90, $leftmargin + 385, $topm + 77, $black, $arial, $full_en);
} else {
    ImageString($im, 2, $leftmargin + 215, $topm - 13, $full_en, $black);
    ImageStringUp($im, 5, $leftmargin + 370, $topm + 78, $full_en, $black);
}
//* Place the name labels*/
$topm = $topmargin + 53;
$topm2 = $topmargin + 5;
ImageCopy($im, $namelabel, $leftmargin + 225, $topm, 0, 0, 144, 39);
ImageCopy($im, $namelabel, $leftmargin + 485, $topm2, 0, 0, 144, 39);
$topm += $yoffset;
$topm2 += $yoffset;
ImageCopy($im, $namelabel, $leftmargin + 205, $topm, 0, 0, 144, 39);
ImageCopy($im, $namelabel, $leftmargin + 435, $topm2, 0, 0, 144, 39);
$topm += $yoffset;
$topm2 += $yoffset;
ImageCopy($im, $namelabel, $leftmargin + 175, $topm, 0, 0, 144, 39);
ImageCopy($im, $namelabel, $leftmargin + 355, $topm2, 0, 0, 144, 39);
$topm += $yoffset;
ImageCopy($im, $namelabel, $leftmargin + 210, $topm, 0, 0, 144, 39);
/* Create the final image */
Imagepng($im);
// Do not edit the following lines
ImageDestroy($wb_lrg);
ImageDestroy($wb_med);
ImageDestroy($wb_sml);
ImageDestroy($wb_bby);
ImageDestroy($im);
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;
}
Example #30
0
}
if ($gnuplottype == 'piri' or $gnuplottype == 'fs20') {
    $message = $messageA . $messageB;
    $f1 = fopen("{$AbsolutPath}/tmp/{$drawuserdef}", "w+");
    fputs($f1, $message);
    fclose($f1);
    exec("{$gnuplot} {$AbsolutPath}/tmp/{$drawuserdef}", $output);
    #echo "output: $output";exit;
    #sleep(3);
    $w = imagesx($im);
    $h = imagesy($im);
    $im2 = imagecreatefrompng("{$AbsolutPath}/tmp/{$gnuplotpng}");
    $w2 = imagesx($im2);
    $h2 = imagesy($im2);
    #ImageCopy($im,$im2,163,10,0,0,$w2,$h2);
    ImageCopy($im, $im2, 153, 5, 0, 0, $w2, $h2);
}
ImageLine($im, $imgmaxxuserdef - $maxcountUSERDEF, 0, $imgmaxxuserdef - $maxcountUSERDEF, $imgmaxyuserdef, $white);
$tempTEMP = $temp;
#############################################################################
$text = $SemanticLong;
$fontsize = 7;
$txtcolor = $bg3p;
ImageTTFText($im, $fontsize, 0, 3, 10, $txtcolor, $fontttf, $text);
$txtcolor = $bg3p;
$fontsize = 9;
$text = $tempTEMP . " " . $SemanticShort;
$tvalue = $tempTEMP;
ImageTTFText($im, $fontsize, 0, 90 - $XcorrectMainTextUSERDEF, 37, $txtcolor, $fontttfb, $text);
$txtcolor = $bg3p;
$fontsize = 7;