Пример #1
0
 /**
  * Method to apply a background color to an image resource.
  *
  * @param   array  $options  An array of options for the filter.
  *                           color  Background matte color
  *
  * @return  void
  *
  * @since   3.4
  * @throws  InvalidArgumentException
  * @deprecated  5.0  Use Joomla\Image\Filter\Backgroundfill::execute() instead
  */
 public function execute(array $options = array())
 {
     // Validate that the color value exists and is an integer.
     if (!isset($options['color'])) {
         throw new InvalidArgumentException('No color value was given. Expected string or array.');
     }
     $colorCode = !empty($options['color']) ? $options['color'] : null;
     // Get resource dimensions
     $width = imagesX($this->handle);
     $height = imagesY($this->handle);
     // Sanitize color
     $rgba = $this->sanitizeColor($colorCode);
     // Enforce alpha on source image
     if (imageIsTrueColor($this->handle)) {
         imageAlphaBlending($this->handle, false);
         imageSaveAlpha($this->handle, true);
     }
     // Create background
     $bg = imageCreateTruecolor($width, $height);
     imageSaveAlpha($bg, empty($rgba['alpha']));
     // Allocate background color.
     $color = imageColorAllocateAlpha($bg, $rgba['red'], $rgba['green'], $rgba['blue'], $rgba['alpha']);
     // Fill background
     imageFill($bg, 0, 0, $color);
     // Apply image over background
     imageCopy($bg, $this->handle, 0, 0, 0, 0, $width, $height);
     // Move flattened result onto curent handle.
     // If handle was palette-based, it'll stay like that.
     imageCopy($this->handle, $bg, 0, 0, 0, 0, $width, $height);
     // Free up memory
     imageDestroy($bg);
     return;
 }
Пример #2
0
<?php

$dest = dirname(realpath(__FILE__)) . '/bug22544.png';
@unlink($dest);
$image = imageCreateTruecolor(640, 100);
$transparent = imageColorAllocate($image, 0, 0, 0);
$red = imageColorAllocate($image, 255, 50, 50);
imageColorTransparent($image, $transparent);
imageFilledRectangle($image, 0, 0, 640 - 1, 100 - 1, $transparent);
imagePng($image, $dest);
echo md5_file($dest) . "\n";
@unlink($dest);
Пример #3
0
/**
* Generate images of alternate sizes.
*/
function resizeImage($cnvrt_arry)
{
    global $platform, $imgs, $cnvrt_path, $reqd_image, $convert_writable, $convert_magick, $convert_GD, $convert_cmd, $cnvrt_alt, $cnvrt_mesgs, $compat_quote;
    if (empty($imgs) || $convert_writable == FALSE) {
        return;
    }
    if ($convert_GD == TRUE && !($gd_version = gdVersion())) {
        return;
    }
    if ($cnvrt_alt['no_prof'] == TRUE) {
        $strip_prof = ' +profile "*"';
    } else {
        $strip_prof = '';
    }
    if ($cnvrt_alt['mesg_on'] == TRUE) {
        $str = '';
    }
    foreach ($imgs as $img_file) {
        if ($cnvrt_alt['indiv'] == TRUE && $img_file != $reqd_image['file']) {
            continue;
        }
        $orig_img = $reqd_image['pwd'] . '/' . $img_file;
        $cnvrtd_img = $cnvrt_path . '/' . $cnvrt_arry['prefix'] . $img_file;
        if (!is_file($cnvrtd_img)) {
            $img_size = GetImageSize($orig_img);
            $height = $img_size[1];
            $width = $img_size[0];
            $area = $height * $width;
            $maxarea = $cnvrt_arry['maxwid'] * $cnvrt_arry['maxwid'] * 0.9;
            $maxheight = $cnvrt_arry['maxwid'] * 0.75 + 1;
            if ($area > $maxarea || $width > $cnvrt_arry['maxwid'] || $height > $maxheight) {
                if ($width / $cnvrt_arry['maxwid'] >= $height / $maxheight) {
                    $dim = 'W';
                }
                if ($height / $maxheight >= $width / $cnvrt_arry['maxwid']) {
                    $dim = 'H';
                }
                if ($dim == 'W') {
                    $cnvt_percent = round(0.9375 * $cnvrt_arry['maxwid'] / $width * 100, 2);
                }
                if ($dim == 'H') {
                    $cnvt_percent = round(0.75 * $cnvrt_arry['maxwid'] / $height * 100, 2);
                }
                // convert it
                if ($convert_magick == TRUE) {
                    // Image Magick image conversion
                    if ($platform == 'Win32' && $compat_quote == TRUE) {
                        $winquote = '"';
                    } else {
                        $winquote = '';
                    }
                    exec($winquote . $convert_cmd . ' -geometry ' . $cnvt_percent . '%' . ' -quality ' . $cnvrt_arry['qual'] . ' -sharpen ' . $cnvrt_arry['sharpen'] . $strip_prof . ' "' . $orig_img . '"' . ' "' . $cnvrtd_img . '"' . $winquote);
                    $using = $cnvrt_mesgs['using IM'];
                } elseif ($convert_GD == TRUE) {
                    // GD image conversion
                    if (eregi('\\.jpg$|\\.jpeg$', $img_file) == TRUE && (imageTypes() & IMG_JPG) == TRUE) {
                        $src_img = imageCreateFromJpeg($orig_img);
                    } elseif (eregi('\\.gif$', $img_file) == TRUE && (imageTypes() & IMG_PNG) == TRUE) {
                        $src_img = imageCreateFromPng($orig_img);
                    } elseif (eregi('\\.gif$', $img_file) == TRUE && (imageTypes() & IMG_GIF) == TRUE) {
                        $src_img = imageCreateFromGif($orig_img);
                    } else {
                        continue;
                    }
                    $src_width = imageSx($src_img);
                    $src_height = imageSy($src_img);
                    $dest_width = $src_width * ($cnvt_percent / 100);
                    $dest_height = $src_height * ($cnvt_percent / 100);
                    if ($gd_version >= 2) {
                        $dst_img = imageCreateTruecolor($dest_width, $dest_height);
                        imageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $src_width, $src_height);
                    } else {
                        $dst_img = imageCreate($dest_width, $dest_height);
                        imageCopyResized($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $src_width, $src_height);
                    }
                    imageDestroy($src_img);
                    if (eregi('\\.jpg$|\\.jpeg$/i', $img_file) == TRUE && (imageTypes() & IMG_JPG) == TRUE) {
                        imageJpeg($dst_img, $cnvrtd_img, $cnvrt_arry['qual']);
                    } elseif (eregi('\\.gif$', $img_file) == TRUE && (imageTypes() & IMG_PNG) == TRUE) {
                        imagePng($dst_img, $cnvrtd_img);
                    } elseif (eregi('\\.gif$/i', $img_file) == TRUE && (imageTypes() & IMG_GIF) == TRUE) {
                        imageGif($dst_img, $cnvrtd_img);
                    }
                    imageDestroy($dst_img);
                    $using = $cnvrt_mesgs['using GD'] . $gd_version;
                }
                if ($cnvrt_alt['mesg_on'] == TRUE && is_file($cnvrtd_img)) {
                    $str .= "  <small>\n" . '   ' . $cnvrt_mesgs['generated'] . $cnvrt_arry['txt'] . $cnvrt_mesgs['converted'] . $cnvrt_mesgs['image_for'] . $img_file . $using . ".\n" . "  </small>\n  <br />\n";
                }
            }
        }
    }
    if (isset($str)) {
        return $str;
    }
}
Пример #4
0
 function _build()
 {
     // scale
     if ($this->_dest_height == -1 || $this->_dest_width == -1) {
         if ($this->_dest_height != -1) {
             $rat = $this->_dest_height / $this->_image_height;
         } else {
             $rat = $this->_dest_width / $this->_image_width;
         }
         $dest_width = ceil($rat * $this->_image_width);
         $dest_height = ceil($rat * $this->_image_height);
         $this->_dest_image = imageCreateTruecolor($dest_width, $dest_height);
         imageCopyResampled($this->_dest_image, $this->_image, 0, 0, 0, 0, $dest_width, $dest_height, $this->_image_width, $this->_image_height);
         return;
     } else {
         $this->_dest_image = imageCreateTruecolor($this->_dest_width, $this->_dest_height);
         $bg_color = ImageColorAllocate($this->_dest_image, 255, 255, 255);
         //imageFill($this->_dest_image,0,0,$bg_color);
         //was causing exhausted memory problems - andy
         imagefilledrectangle($this->_dest_image, 0, 0, $this->_dest_width, $this->_dest_height, $bg_color);
         $imagemaxratio = $this->_dest_width / $this->_dest_height;
         $imageratio = $this->_image_width / $this->_image_height;
         // basically eliminate the white space by swapping the ratios
         if ($this->_auto_crop) {
             $tmp = $imagemaxratio;
             $imagemaxratio = $imageratio;
             $imageratio = $tmp;
             unset($tmp);
         }
         if ($this->_keep_if_smaller && $this->_image_width <= $this->_dest_width && $this->_image_height <= $this->_dest_height) {
             $dest_width = $this->_image_width;
             $dest_height = $this->_image_height;
         } else {
             if ($imageratio > $imagemaxratio) {
                 $dest_width = $this->_dest_width;
                 $dest_height = ceil($this->_dest_width / $this->_image_width * $this->_image_height);
             } else {
                 if ($imageratio < $imagemaxratio) {
                     $dest_height = $this->_dest_height;
                     $dest_width = ceil($this->_dest_height / $this->_image_height * $this->_image_width);
                 } else {
                     $dest_width = $this->_dest_width;
                     $dest_height = $this->_dest_height;
                 }
             }
         }
     }
     // center
     if ($this->_auto_center) {
         $dest_x = ($this->_dest_width - $dest_width) / 2;
         $dest_y = ($this->_dest_height - $dest_height) / 2;
     } else {
         $dest_x = 0;
         $dest_y = 0;
     }
     //var_dump($dest_width);
     //var_dump($dest_height);
     // resize
     if ($this->_high_quality) {
         imageCopyResampled($this->_dest_image, $this->_image, $dest_x, $dest_y, 0, 0, $dest_width, $dest_height, $this->_image_width, $this->_image_height);
     } else {
         imageCopyResized($this->_dest_image, $this->_image, $dest_x, $dest_y, 0, 0, $dest_width, $dest_height, $this->_image_width, $this->_image_height);
     }
 }
Пример #5
0
    /**
     * Resize an image
     *
     * @param string  $filename Image filename
     * @param integer $width    Image width
     * @param integer $height   Image height
     *
     * @return mixed
     */
    public function proceed($filename, $width, $height)
    {
        $image = $this->_openImage($filename);

        if ($image === null) {
            throw new Juila_Exception('Unable to create image');
        }

        list($image, $src_width, $src_height) = $image;
        $thumb = imageCreateTruecolor($width, $height);

        $resize = imageCopyResampled(
            $thumb,
            $image,
            0, 0,
            0, 0,
            $width, $height,
            $src_width, $src_height
        );
        if ( ! $resize) {
            throw new Juila_Exception('Unable to resize image');
        }

        imageDestroy($image);

        ob_start();
        imagePNG($thumb);
        $data = ob_get_clean();

        imageDestroy($thumb);

        return array($data, 'image/png');
    }
Пример #6
0
function makeBoardImage($direction)
{
    $squareSize = getSquareSize();
    $decorationWidth = getDecorationWidth();
    $coordinateWidth = getCoordinateWidth();
    $borderWidth = getBorderWidth();
    $numRows = 8 * $squareSize + 2 * $decorationWidth;
    $numCols = $numRows;
    $im = imageCreateTruecolor($numRows, $numCols);
    imageAlphaBlending($im, 1);
    $dark_square_color = getDarkSquareColor($im);
    $light_square_color = getLightSquareColor($im);
    $outline_color = getOutlineColor($im);
    $white = imageColorAllocate($im, 255, 255, 255);
    imageFilledRectangle($im, 0, 0, $numRows - 1, $numCols - 1, $outline_color);
    if (isCoordinatesEnabled()) {
        imageFilledRectangle($im, $borderWidth, $borderWidth, $numRows - $borderWidth - 1, $numCols - $borderWidth - 1, $white);
        imageFilledRectangle($im, $borderWidth + $coordinateWidth, $borderWidth + $coordinateWidth, $numRows - $borderWidth - $coordinateWidth - 1, $numCols - $borderWidth - $coordinateWidth - 1, $outline_color);
    }
    for ($rank = 0; $rank < 8; $rank++) {
        for ($file = 0; $file < 8; $file++) {
            $square_color = ($rank + $file) % 2 ? $dark_square_color : $light_square_color;
            $x1 = $file * $squareSize + $decorationWidth;
            $y1 = $rank * $squareSize + $decorationWidth;
            $x2 = $x1 + $squareSize - 1;
            $y2 = $y1 + $squareSize - 1;
            imageFilledRectangle($im, $x1, $y1, $x2, $y2, $square_color);
        }
    }
    addCoordinates($im, $direction);
    return $im;
}
Пример #7
0
 protected function handleAvatar()
 {
     // something happened in the last years: those textures do not include tiny icons
     $sizes = ['small' => 18, 'medium' => 36, 'large' => 56];
     $aPath = 'uploads/avatars/%d.jpg';
     $s = $this->_get['size'] ?: 'medium';
     if (!$this->_get['id'] || !preg_match('/^([0-9]+)\\.(jpg|gif)$/', $this->_get['id'][0], $matches) || !in_array($s, array_keys($sizes))) {
         return;
     }
     $this->contentType = 'image/' . $matches[2];
     $id = $matches[1];
     $dest = imageCreateTruecolor($sizes[$s], $sizes[$s]);
     if (file_exists(sprintf($aPath, $id))) {
         $offsetX = $offsetY = 0;
         switch ($s) {
             case 'tiny':
                 $offsetX += $sizes['small'];
             case 'small':
                 $offsetY += $sizes['medium'];
             case 'medium':
                 $offsetX += $sizes['large'];
         }
         $src = imageCreateFromJpeg(printf($aPath, $id));
         imagecopymerge($dest, $src, 0, 0, $offsetX, $offsetY, $sizes[$s], $sizes[$s], 100);
     }
     if ($matches[2] == 'gif') {
         imageGif($dest);
     } else {
         imageJpeg($dest);
     }
     return;
 }
Пример #8
0
 private function profile_handleAvatar()
 {
     // something happened in the last years: those textures do not include tiny icons
     $s = ['small' => 18, 'medium' => 36, 'large' => 56];
     $size = $this->get('size') ?: 'medium';
     if (!$this->get('id') || !preg_match('/^([0-9]+)\\.(jpg|gif)$/', $this->get('id'), $matches) || !in_array($size, array_keys($s))) {
         return false;
     }
     header('Content-Type: image/' . $matches[2]);
     $id = $matches[1];
     $dest = imageCreateTruecolor($s[$size], $s[$size]);
     if (file_exists('uploads/avatars/' . $id . '.jpg')) {
         $offsetX = $offsetY = 0;
         switch ($size) {
             case 'tiny':
                 $offsetX += $s['small'];
             case 'small':
                 $offsetY += $s['medium'];
             case 'medium':
                 $offsetX += $s['large'];
         }
         $src = imageCreateFromJpeg('uploads/avatars/' . $id . '.jpg');
         imagecopymerge($dest, $src, 0, 0, $offsetX, $offsetY, $s[$size], $s[$size], 100);
     }
     if ($matches[2] == 'gif') {
         imageGif($dest);
     } else {
         imageJpeg($dest);
     }
     return true;
 }
Пример #9
0
         if (isset($zsfCfg['distortion']) && $zsfCfg['distortion'] == 1) {
             $x = $x + (sin($x * $zsfRand[0] + $zsfRand[4]) + sin($y * $zsfRand[2] + $zsfRand[5])) * $zsfRand[8] + 2;
             $y = $y + (sin($x * $zsfRand[1] + $zsfRand[6]) + sin($y * $zsfRand[3] + $zsfRand[7])) * $zsfRand[9] + 3;
         }
         imageSetPixel($zsfIm, $x, $y, $zsfImFg);
     }
     $thisZsfCfg['offX'] += $imgFontEngWidth[$zsfQv] + $thisZsfCfg['letter-spacing-ratio'];
 }
 # 리사이징된 이미지 폭, 높이 구하기
 $thisZsfCfg['imReW'] = round($thisZsfCfg['imW'] * $thisZsfCfg['font-size'] / $thisZsfCfg['imH']) + $thisZsfCfg['padding-left'] * 2 + $thisZsfCfg['logoW'];
 if ($thisZsfCfg['imReW'] < $thisZsfCfg['width']) {
     $thisZsfCfg['imReW'] = $thisZsfCfg['width'];
 }
 $thisZsfCfg['imReH'] = $thisZsfCfg['height'];
 # 리사이징된 이미지 설정
 $zsfImRe = imageCreateTruecolor($thisZsfCfg['imReW'], $thisZsfCfg['imReH']);
 imagefill($zsfImRe, 0, 0, $zsfImBg);
 imageCopyResampled($zsfImRe, $zsfIm, $thisZsfCfg['padding-left'], $thisZsfCfg['padding-top'], 0, 0, round($thisZsfCfg['imW'] * $thisZsfCfg['font-size'] / $thisZsfCfg['imH']), $thisZsfCfg['font-size'], $thisZsfCfg['imW'], $thisZsfCfg['imH']);
 imageDestroy($zsfIm);
 imageFilledRectangle($zsfImRe, $thisZsfCfg['imReW'] - $thisZsfCfg['logoW'], 0, $thisZsfCfg['imReW'], $thisZsfCfg['imReH'], $zsfImFg);
 if ($zsfCfg['zsfLogo']) {
     # 로고 새김
     $thisZsfCfg['logoOffX'] = $thisZsfCfg['imReW'] - $thisZsfCfg['logoW'] + 3;
     $thisZsfCfg['logoOffY'] = ($thisZsfCfg['imReH'] - 12) / 2;
     foreach ($zsfLogoMap as $v) {
         imageSetPixel($zsfImRe, substr($v, 0, 2) * 1 + $thisZsfCfg['logoOffX'], substr($v, -2) * 1 + $thisZsfCfg['logoOffY'], $zsfImBg);
     }
 }
 if ($thisZsfCfg['border-color']) {
     $zsfImBd = imageColorAllocate($zsfImRe, hexdec(substr($thisZsfCfg['border-color'], 1, 2)), hexdec(substr($thisZsfCfg['border-color'], 3, 2)), hexdec(substr($thisZsfCfg['border-color'], -2)));
 } else {