Пример #1
0
function save_resize($tempDir, $imgurl, $w, $h, $destDir)
{
    //print ("save_resize...\n<br />");
    //print ("$tempDir\n<br />");
    //print ("$imgurl\n<br />");
    //print ("$w<br />\n");
    //print ("$h<br />\n");
    //print ("$destDir<br />\n");
    $simg = imagecreatefromjpeg("{$tempDir}" . $imgurl);
    // Make A New Temporary Image To Create The Thumbanil From
    $currwidth = imagesx($simg);
    // Current Image Width
    $currheight = imagesy($simg);
    // Current Image Height
    //print ("$currwidth<br />\n");
    //print ("$currheight<br />\n");
    //if ($currheight > $currwidth) {   // If Height Is Greater Than Width
    //   $zoom = $w / $currheight;   // Length Ratio For Width
    //   $newheight = $h;   // Height Is Equal To Max Height
    //   $newwidth = $currwidth * $zoom;   // Creates The New Width
    //} else {    // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height)
    $zoom = $w / $currwidth;
    // Length Ratio For Height
    $newwidth = $w;
    // Width Is Equal To Max Width
    $newheight = $currheight * $zoom;
    // Creates The New Height
    //}
    //print ("$newwidth<br />\n");
    //print ("$newheight<br />\n");
    $dimg = imagecreate($newwidth, $newheight);
    // Make New Image For Thumbnail
    imagetruecolortopalette($simg, false, 256);
    // Create New Color Pallete
    $palsize = ImageColorsTotal($simg);
    for ($i = 0; $i < $palsize; $i++) {
        // Counting Colors In The Image
        $colors = ImageColorsForIndex($simg, $i);
        // Number Of Colors Used
        ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']);
        // Tell The Server What Colors This Image Will Use
    }
    imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);
    // Copy Resized Image To The New Image (So We Can Save It)
    imagejpeg($dimg, "{$destDir}" . $imgurl);
    // Saving The Image
    //print ("$destDir" . $imgurl . "<br />");
    imagedestroy($simg);
    // Destroying The Temporary Image
    imagedestroy($dimg);
    // Destroying The Other Temporary Image
    return $newheight;
    //print ("save_resize DONE...");
}
Пример #2
0
function traiter_image($nomorig, $dest_width, $dest_height, $opacite, $nb, $miroir, $exact, $couleurfond, &$type)
{
    list($width_orig, $height_orig, $type, $attr) = getimagesize($nomorig);
    if (!$width_orig) {
        return false;
    }
    if ($dest_width == NULL) {
        $dest_width = $width_orig;
    }
    if ($dest_height == NULL) {
        $dest_height = $height_orig;
    }
    $width_diff = $dest_width / $width_orig;
    $height_diff = $dest_height / $height_orig;
    $delta_x = $delta_y = $border_width = $border_height = 0;
    if ($width_diff > 1 and $height_diff > 1) {
        $next_width = $width_orig;
        $next_height = $height_orig;
        $dest_width = intval($exact) == 1 ? $dest_width : $next_width;
        $dest_height = intval($exact) == 1 ? $dest_height : $next_height;
    } else {
        if ($width_diff > $height_diff) {
            $next_height = $dest_height;
            $next_width = intval($width_orig * $next_height / $height_orig);
            if ($exact == IMAGE_REDIM_RECADRE) {
                $dest_ratio = $dest_width / $width_orig;
                $ho = $dest_height / $dest_ratio;
                $delta_y = ($height_orig - $ho) / 2;
                $height_orig = $ho;
                $next_width = $dest_width;
            } else {
                if ($exact != IMAGE_REDIM_BORDURE) {
                    $dest_width = $next_width;
                }
            }
        } else {
            $next_width = $dest_width;
            $next_height = intval($height_orig * $dest_width / $width_orig);
            if ($exact == IMAGE_REDIM_RECADRE) {
                $dest_ratio = $dest_height / $height_orig;
                $wo = $dest_width / $dest_ratio;
                $delta_x = ($width_orig - $wo) / 2;
                $width_orig = $wo;
                $next_height = $dest_height;
            } else {
                if ($exact != IMAGE_REDIM_BORDURE) {
                    $dest_height = $next_height;
                }
            }
        }
    }
    if ($exact == IMAGE_REDIM_BORDURE) {
        $border_width = intval(($dest_width - $next_width) / 2);
        $border_height = intval(($dest_height - $next_height) / 2);
    }
    $image_new = imagecreatetruecolor($dest_width, $dest_height);
    switch ($type) {
        case IMAGETYPE_GIF:
            $image_orig = imagecreatefromgif($nomorig);
            break;
        case IMAGETYPE_JPEG:
        default:
            $image_orig = imagecreatefromjpeg($nomorig);
            break;
        case IMAGETYPE_PNG:
            $image_orig = imagecreatefrompng($nomorig);
            break;
    }
    // Preparer la couleur de fond (pour bordures, transparence, miroir)
    if ($couleurfond == '') {
        $couleurfond = 'ffffff';
    }
    $fondrgb = hex2RGB($couleurfond);
    // Définir la couleur de fond générale
    $bgcolor = imagecolorallocate($image_new, $fondrgb['red'], $fondrgb['green'], $fondrgb['blue']);
    // Préserver la transparence des gifs et png
    if ($type != IMAGETYPE_JPEG) {
        $trnprt_indx = imagecolortransparent($image_orig);
        // If we have a specific transparent color
        if ($trnprt_indx >= 0) {
            // Get the original image's transparent color's RGB values
            $trnprt_color = imagecolorsforindex($image_orig, $trnprt_indx);
            // Allocate the same color in the new image resource
            $trnprt_indx = imagecolorallocate($image_new, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
            // Completely fill the background of the new image with allocated color.
            imagefill($image_new, 0, 0, $trnprt_indx);
            // Set the background color for new image to transparent
            imagecolortransparent($image_new, $trnprt_indx);
        } else {
            // Turn off transparency blending (temporarily)
            imagealphablending($image_new, false);
            // Create a new transparent color for image
            $color = imagecolorallocatealpha($image_new, 0, 0, 0, 127);
            // Completely fill the background of the new image with allocated color.
            imagefill($image_new, 0, 0, $color);
            // Restore transparency blending
            imagesavealpha($image_new, true);
            // Remplir avec la couleur de fond
            imagefill($image_new, 0, 0, $bgcolor);
        }
    } else {
        // Remplir avec la couleur de fond
        imagefill($image_new, 0, 0, $bgcolor);
    }
    if ($opacite != "") {
        $opac_img = imagecreatetruecolor($width_orig, $height_orig);
        imagefill($opac_img, 0, 0, $bgcolor);
        imagecopymerge($opac_img, $image_orig, 0, 0, 0, 0, $width_orig, $height_orig, $opacite);
        $image_orig = $opac_img;
    }
    // Redimensionnement, avec ajout éventuel de bordures.
    imagecopyresampled($image_new, $image_orig, $border_width, $border_height, $delta_x, $delta_y, $next_width, $next_height, $width_orig, $height_orig);
    // Noir et blanc
    if ($nb != "") {
        imagetruecolortopalette($image_new, false, 256);
        $total = ImageColorsTotal($image_new);
        for ($i = 0; $i < $total; $i++) {
            $old = ImageColorsForIndex($image_new, $i);
            $commongrey = (int) (($old['red'] + $old['green'] + $old['blue']) / 3);
            ImageColorSet($image_new, $i, $commongrey, $commongrey, $commongrey);
        }
    }
    if ($miroir != "") {
        $mh = intval($miroir) == 1 ? 50 : intval($miroir);
        $largeur = imagesx($image_new);
        $hauteur = imagesy($image_new);
        $temporaireUn = imagecreatetruecolor($largeur, $mh);
        $temporaireDeux = imagecreatetruecolor($largeur, $mh);
        $resultat = imagecreatetruecolor($largeur, $hauteur + $mh);
        imagefill($resultat, 1, 1, $bgcolor);
        imagefill($temporaireDeux, 1, 1, $bgcolor);
        imagecopy($resultat, $image_new, 0, 0, 0, 0, $largeur, $hauteur);
        imagecopy($temporaireUn, $image_new, 0, 0, 0, $hauteur - $mh, $largeur, $mh);
        effet_miroir($temporaireDeux, $temporaireUn);
        imagecopy($resultat, $temporaireDeux, 0, $hauteur, 0, 0, $largeur, $mh);
        $image_new = $resultat;
    }
    return $image_new;
}
 /**
  * Reduce colors in image dependend on the actual amount of colors (Only works if we are not in truecolor mode)
  * This function is not needed anymore, as truecolor is now always on.
  *
  * @param	integer		GDlib Image Pointer
  * @param	integer		The max number of colors in the image before a reduction will happen; basically this means that IF the GD image current has the same amount or more colors than $limit define, THEN a reduction is performed.
  * @param	integer		Number of colors to reduce the image to.
  * @return	void
  * @deprecated since TYPO3 4.4, this function will be removed in TYPO3 4.6.
  */
 function reduceColors(&$im, $limit, $cols)
 {
     t3lib_div::logDeprecatedFunction();
     if (!$this->truecolor && ImageColorsTotal($im) >= $limit) {
         $this->makeEffect($im, array('value' => 'colors=' . $cols));
     }
 }
Пример #4
0
 /**
  * Resample the image 
  * http://www.php.net/manual/en/function.imagecopyresized.php
  */
 protected function resampleBicubic(&$dst, &$src, $dstx, $dsty, $srcx, $srcy, $w, $h, $zoomX, $zoomY = '')
 {
     if (!$zoomY) {
         $zoomY = $zoomX;
     }
     $palsize = ImageColorsTotal($src);
     for ($i = 0; $i < $palsize; $i++) {
         $colors = ImageColorsForIndex($src, $i);
         ImageColorAllocate($dst, $colors['red'], $colors['green'], $colors['blue']);
     }
     $zoomX2 = (int) ($zoomX / 2);
     $zoomY2 = (int) ($zoomY / 2);
     $dstX = imagesx($dst);
     $dstY = imagesy($dst);
     $srcX = imagesx($src);
     $srcY = imagesy($src);
     for ($j = 0; $j < $h - $dsty; $j++) {
         $sY = (int) ($j * $zoomY) + $srcy;
         $y13 = $sY + $zoomY2;
         $dY = $j + $dsty;
         if ($sY >= $srcY or $dY >= $dstY or $y13 >= $srcY) {
             break 1;
         }
         for ($i = 0; $i < $w - $dstx; $i++) {
             $sX = (int) ($i * $zoomX) + $srcx;
             $x34 = $sX + $zoomX2;
             $dX = $i + $dstx;
             if ($sX >= $srcX or $dX >= $dstX or $x34 >= $srcX) {
                 break 1;
             }
             $c1 = ImageColorsForIndex($src, ImageColorAt($src, $sX, $y13));
             $c2 = ImageColorsForIndex($src, ImageColorAt($src, $sX, $sY));
             $c3 = ImageColorsForIndex($src, ImageColorAt($src, $x34, $y13));
             $c4 = ImageColorsForIndex($src, ImageColorAt($src, $x34, $sY));
             $r = ($c1['red'] + $c2['red'] + $c3['red'] + $c4['red']) / 4;
             $g = ($c1['green'] + $c2['green'] + $c3['green'] + $c4['green']) / 4;
             $b = ($c1['blue'] + $c2['blue'] + $c3['blue'] + $c4['blue']) / 4;
             ImageSetPixel($dst, $dX, $dY, ImageColorClosest($dst, $r, $g, $b));
         }
     }
 }
 /**
  * Apply input levels to input image pointer (increasing contrast)
  *
  * @param integer $im GDlib Image Pointer
  * @param integer $low The "low" value (close to 0)
  * @param integer $high The "high" value (close to 255)
  * @param boolean $swap If swap, then low and high are swapped. (Useful for negated masks...)
  * @return void
  * @todo Define visibility
  */
 public function inputLevels(&$im, $low, $high, $swap = '')
 {
     if ($low < $high) {
         $low = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($low, 0, 255);
         $high = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($high, 0, 255);
         if ($swap) {
             $temp = $low;
             $low = 255 - $high;
             $high = 255 - $temp;
         }
         $delta = $high - $low;
         $totalCols = ImageColorsTotal($im);
         for ($c = 0; $c < $totalCols; $c++) {
             $cols = ImageColorsForIndex($im, $c);
             $cols['red'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange(($cols['red'] - $low) / $delta * 255, 0, 255);
             $cols['green'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange(($cols['green'] - $low) / $delta * 255, 0, 255);
             $cols['blue'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange(($cols['blue'] - $low) / $delta * 255, 0, 255);
             ImageColorSet($im, $c, $cols['red'], $cols['green'], $cols['blue']);
         }
     }
 }
Пример #6
0
     $newwidth = $currwidth * $zoom;
     // Creates The New Width
 } else {
     // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height)
     $zoom = $twidth / $currwidth;
     // Length Ratio For Height
     $newwidth = $twidth;
     // Width Is Equal To Max Width
     $newheight = $currheight * $zoom;
     // Creates The New Height
 }
 $dimg = imagecreate($newwidth, $newheight);
 // Make New Image For Thumbnail
 imagetruecolortopalette($simg, false, 256);
 // Create New Color Pallete
 $palsize = ImageColorsTotal($simg);
 for ($i = 0; $i < $palsize; $i++) {
     // Counting Colors In The Image
     $colors = ImageColorsForIndex($simg, $i);
     // Number Of Colors Used
     ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']);
     // Tell The Server What Colors This Image Will Use
 }
 imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);
 // Copy Resized Image To The New Image (So We Can Save It)
 imagejpeg($dimg, "{$tdir}" . $_SESSION['user']['username'] . '.jpg');
 // Saving The Image
 imagedestroy($simg);
 // Destroying The Temporary Image
 imagedestroy($dimg);
 // Destroying The Other Temporary Image
Пример #7
0
 /**
  * From: https://stackoverflow.com/questions/4590441/php-thumbnail-image-resizing-with-proportions
  */
 function resize(&$img, $size)
 {
     $pm = new PictshareModel();
     $sd = $pm->sizeStringToWidthHeight($size);
     $maxwidth = $sd['width'];
     $maxheight = $sd['height'];
     $width = imagesx($img);
     $height = imagesy($img);
     if (!ALLOW_BLOATING) {
         if ($maxwidth > $width) {
             $maxwidth = $width;
         }
         if ($maxheight > $height) {
             $maxheight = $height;
         }
     }
     if ($height > $width) {
         $ratio = $maxheight / $height;
         $newheight = $maxheight;
         $newwidth = $width * $ratio;
     } else {
         $ratio = $maxwidth / $width;
         $newwidth = $maxwidth;
         $newheight = $height * $ratio;
     }
     $newimg = imagecreatetruecolor($newwidth, $newheight);
     $palsize = ImageColorsTotal($img);
     for ($i = 0; $i < $palsize; $i++) {
         $colors = ImageColorsForIndex($img, $i);
         ImageColorAllocate($newimg, $colors['red'], $colors['green'], $colors['blue']);
     }
     imagefill($newimg, 0, 0, IMG_COLOR_TRANSPARENT);
     imagesavealpha($newimg, true);
     imagealphablending($newimg, true);
     imagecopyresampled($newimg, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
     $img = $newimg;
 }
Пример #8
0
 public function __invoke()
 {
     $view = $this->view;
     $pixObject = $this->pixObject;
     $id = $pixObject->getId();
     $title = $pixObject->getTitle();
     $pixname = $pixObject->getPicture();
     $filepix = "/usr/local/apache2/html/uploads/";
     $filepix .= $this->username;
     $filepix .= "/pix/";
     $pix = $filepix . $pixname;
     // Check to see that the thumbnail exists.
     $thumbPixName = "large_" . $pixname;
     $thumbPix = $filepix . $thumbPixName;
     if (!file_exists($thumbPix)) {
         $img = imagecreatefromjpeg($pix);
         $width = imagesx($img);
         $height = imagesy($img);
         $whlog = "width: " . $width . " height " . $height;
         //determine which side is the longest to use in calculating length of the shorter side, since the longest will be the max size for whichever side is longest.
         if ($height > $width) {
             $ratio = 160 / $height;
             $newheight = 160;
             $newwidth = $width * $ratio;
         } else {
             $ratio = 160 / $width;
             $newwidth = 160;
             $newheight = $height * $ratio;
         }
         $whlog = "newwidth: " . $newwidth . " newheight " . $newheight;
         //create new image resource to hold the resized image
         $newimg = imagecreatetruecolor($newwidth, $newheight);
         $palsize = ImageColorsTotal($img);
         //Get palette size for original image
         for ($i = 0; $i < $palsize; $i++) {
             $colors = ImageColorsForIndex($img, $i);
             ImageColorAllocate($newimg, $colors['red'], $colors['green'], $colors['blue']);
         }
         //copy original image into new image at new size.
         imagecopyresized($newimg, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
         imagejpeg($newimg, $thumbPix);
         //$output file is the path/filename where you wish to save the file.
     }
     $base = 'https://newhollandpress.com/pix/view/';
     $base .= urlencode($id);
     return $view->partial("/items/pix.phtml");
     /*
         	$output = "<div id='" . $this->itemId . "' class='itemHelper_Wide'>";
     		$output .= "<ul>";
     		$output .= "<li>";
     		$output .= "<span>Pix</span>";
     		$output .= "</li>";
     		$output .= "<li>";
     		$output .= "<a href='" . $base . "'>" . $id . "</a>";
     		$output .= "</li>";
     		$output .= "<li>";
     		$output .= $pixObject->getPicture();
     		$output .= "</li>";
     		$output .= "<li>";
     		$output .= "<img src='https://www.newhollandpress.com/uploads/";
     		$output .= $this->username;
     		$output .= "/pix/";
     		$output .= $thumbPixName;
     		$output .= "'>";
     		$output .= "</li>";
     		$output .= "</ul>";
     		$output .= "</div>";
     		
     		return $output;
     * 
     */
 }
Пример #9
0
 function GDtoICOstr(&$gd_ico_array)
 {
     foreach ($gd_ico_array as $key => $gd_image) {
         $IcoWidths[$key] = ImageSX($gd_image);
         $IcoHeights[$key] = ImageSY($gd_image);
         $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
         $totalcolors[$key] = ImageColorsTotal($gd_image);
         $icXOR[$key] = '';
         for ($y = $IcoHeights[$key] - 1; $y >= 0; $y--) {
             for ($x = 0; $x < $IcoWidths[$key]; $x++) {
                 $argb = $this->gpc($gd_image, $x, $y);
                 $a = round(255 * ((127 - $argb['alpha']) / 127));
                 $r = $argb['red'];
                 $g = $argb['green'];
                 $b = $argb['blue'];
                 if ($bpp[$key] == 32) {
                     $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
                 } elseif ($bpp[$key] == 24) {
                     $icXOR[$key] .= chr($b) . chr($g) . chr($r);
                 }
                 if ($a < 128) {
                     @($icANDmask[$key][$y] .= '1');
                 } else {
                     @($icANDmask[$key][$y] .= '0');
                 }
             }
             while (strlen($icANDmask[$key][$y]) % 32) {
                 $icANDmask[$key][$y] .= '0';
             }
         }
         $icAND[$key] = '';
         foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
             for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
                 $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
             }
         }
     }
     foreach ($gd_ico_array as $key => $gd_image) {
         $biSizeImage = $IcoWidths[$key] * $IcoHeights[$key] * ($bpp[$key] / 8);
         $bfh[$key] = '';
         $bfh[$key] .= "(";
         $bfh[$key] .= $this->le2s($IcoWidths[$key], 4);
         $bfh[$key] .= $this->le2s($IcoHeights[$key] * 2, 4);
         $bfh[$key] .= "";
         $bfh[$key] .= chr($bpp[$key]) . "";
         $bfh[$key] .= "";
         $bfh[$key] .= $this->le2s($biSizeImage, 4);
         $bfh[$key] .= "";
         $bfh[$key] .= "";
         $bfh[$key] .= "";
         $bfh[$key] .= "";
     }
     $icondata = "";
     $icondata .= "";
     $icondata .= $this->le2s(count($gd_ico_array), 2);
     $dwImageOffset = 6 + count($gd_ico_array) * 16;
     foreach ($gd_ico_array as $key => $gd_image) {
         $icondata .= chr($IcoWidths[$key]);
         $icondata .= chr($IcoHeights[$key]);
         $icondata .= chr($totalcolors[$key]);
         $icondata .= "";
         $icondata .= "";
         $icondata .= chr($bpp[$key]) . "";
         $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
         $icondata .= $this->le2s($dwBytesInRes, 4);
         $icondata .= $this->le2s($dwImageOffset, 4);
         $dwImageOffset += strlen($bfh[$key]);
         $dwImageOffset += strlen($icXOR[$key]);
         $dwImageOffset += strlen($icAND[$key]);
     }
     foreach ($gd_ico_array as $key => $gd_image) {
         $icondata .= $bfh[$key];
         $icondata .= $icXOR[$key];
         $icondata .= $icAND[$key];
     }
     return $icondata;
 }
Пример #10
0
 function nfo2pic($pic_format)
 {
     // 打开指定位置的 NFO 文件
     $nfoa = @file($this->config['nfo-dir'] . $this->config['nfo_name']);
     // 如果 NFO 文件不存在,或者打开失败
     if (!$nfoa) {
         echo "打开打开NFO文件失败!";
         exit;
     }
     // 计算图片的高度
     $this->setvar("height", count($nfoa) * $this->config["line-space"]);
     // 建立图片流
     $im = imagecreate($this->config["width"], $this->config["height"]);
     // 获取背景色
     $bgR = hexdec(substr($this->config['bgcolor'], 1, 2));
     $bgG = hexdec(substr($this->config['bgcolor'], 3, 2));
     $bgB = hexdec(substr($this->config['bgcolor'], 5));
     //list ($bgR,  $bgG,  $bgB)  =  $this->config['bgcolor'];
     // 设置背景色
     $background_color = imagecolorallocate($im, $bgR, $bgG, $bgB);
     // 获取文字颜色
     $fgR = hexdec(substr($this->config['fontcolor'], 1, 2));
     $fgG = hexdec(substr($this->config['fontcolor'], 3, 2));
     $fgB = hexdec(substr($this->config['fontcolor'], 5));
     //list ($fgR,  $fgG,  $fgB)  =  $this->config['fontcolor'];
     // 设置字体颜色
     $font_color = imagecolorallocate($im, $fgR, $fgG, $fgB);
     // 检查是否需要将背景色透明
     if ($this->config["tbg"]) {
         ImageColorTransparent($im, $background_color);
     }
     // 每一行的行距变量
     $pheight = 0;
     // 输出 NFO 的内容
     for ($i = 0; $i < count($nfoa); $i++) {
         $pheight = $pheight + $this->config["line-space"];
         imagettftext($im, $this->config["font-size"], 0, $this->config["left"], $pheight, $font_color, $this->config['font-dir'] . $this->config["font-name"], $this->format_text($nfoa[$i]));
     }
     // 检查输出格式
     if ($pic_format == "png") {
         @imagepng($im, $this->config["server_save_dir"] . $this->config["pic_name"]);
     }
     if ($pic_format == "gif") {
         @imagegif($im, $this->config["server_save_dir"] . $this->config["pic_name"]);
     }
     if ($pic_format == "jpg") {
         //$this->config["pic_name"] = $this->config["prefix"]."_".md5(mktime()).".jpg";
         @imagejpeg($im, $this->config["server_save_dir"] . $this->config["pic_name"], $this->config["jepg_quality"]);
     }
     $this->color_total = ImageColorsTotal($im);
     // 释放图片流
     imagedestroy($im);
 }
 /**
  * Apply input levels to input image pointer (increasing contrast)
  *
  * @param resource $im GDlib Image Pointer
  * @param int $low The "low" value (close to 0)
  * @param int $high The "high" value (close to 255)
  * @return void
  */
 public function inputLevels(&$im, $low, $high)
 {
     if ($low < $high) {
         $low = MathUtility::forceIntegerInRange($low, 0, 255);
         $high = MathUtility::forceIntegerInRange($high, 0, 255);
         $delta = $high - $low;
         $totalCols = ImageColorsTotal($im);
         for ($c = 0; $c < $totalCols; $c++) {
             $cols = ImageColorsForIndex($im, $c);
             $cols['red'] = MathUtility::forceIntegerInRange(($cols['red'] - $low) / $delta * 255, 0, 255);
             $cols['green'] = MathUtility::forceIntegerInRange(($cols['green'] - $low) / $delta * 255, 0, 255);
             $cols['blue'] = MathUtility::forceIntegerInRange(($cols['blue'] - $low) / $delta * 255, 0, 255);
             ImageColorSet($im, $c, $cols['red'], $cols['green'], $cols['blue']);
         }
     }
 }
Пример #12
0
 function ImageResize(&$src, $x, $y)
 {
     $dst = imagecreatetruecolor($x, $y);
     $pals = ImageColorsTotal($src);
     for ($i = 0; $i < $pals; $i++) {
         $colors = ImageColorsForIndex($src, $i);
         ImageColorAllocate($dst, $colors['red'], $colors['green'], $colors['blue']);
     }
     $scX = (imagesx($src) - 1) / $x;
     $scY = (imagesy($src) - 1) / $y;
     $scX2 = intval($scX / 2);
     $scY2 = intval($scY / 2);
     for ($j = 0; $j < $y; $j++) {
         $sY = intval($j * $scY);
         $y13 = $sY + $scY2;
         for ($i = 0; $i < $x; $i++) {
             $sX = intval($i * $scX);
             $x34 = $sX + $scX2;
             $c1 = ImageColorsForIndex($src, ImageColorAt($src, $sX, $y13));
             $c2 = ImageColorsForIndex($src, ImageColorAt($src, $sX, $sY));
             $c3 = ImageColorsForIndex($src, ImageColorAt($src, $x34, $y13));
             $c4 = ImageColorsForIndex($src, ImageColorAt($src, $x34, $sY));
             $r = ($c1['red'] + $c2['red'] + $c3['red'] + $c4['red']) / 4;
             $g = ($c1['green'] + $c2['green'] + $c3['green'] + $c4['green']) / 4;
             $b = ($c1['blue'] + $c2['blue'] + $c3['blue'] + $c4['blue']) / 4;
             ImageSetPixel($dst, $i, $j, ImageColorClosest($dst, $r, $g, $b));
         }
     }
     return $dst;
 }
Пример #13
0
 function GD2ICOstring(&$gd_image_array)
 {
     foreach ($gd_image_array as $key => $gd_image) {
         $ImageWidths[$key] = ImageSX($gd_image);
         $ImageHeights[$key] = ImageSY($gd_image);
         $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
         $totalcolors[$key] = ImageColorsTotal($gd_image);
         $icXOR[$key] = '';
         for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
             for ($x = 0; $x < $ImageWidths[$key]; $x++) {
                 $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
                 $a = round(255 * ((127 - $argb['alpha']) / 127));
                 $r = $argb['red'];
                 $g = $argb['green'];
                 $b = $argb['blue'];
                 if ($bpp[$key] == 32) {
                     $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
                 } elseif ($bpp[$key] == 24) {
                     $icXOR[$key] .= chr($b) . chr($g) . chr($r);
                 }
                 if ($a < 128) {
                     @($icANDmask[$key][$y] .= '1');
                 } else {
                     @($icANDmask[$key][$y] .= '0');
                 }
             }
             // mask bits are 32-bit aligned per scanline
             while (strlen($icANDmask[$key][$y]) % 32) {
                 $icANDmask[$key][$y] .= '0';
             }
         }
         $icAND[$key] = '';
         foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
             for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
                 $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
             }
         }
     }
     foreach ($gd_image_array as $key => $gd_image) {
         $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
         // BITMAPINFOHEADER - 40 bytes
         $BitmapInfoHeader[$key] = '';
         $BitmapInfoHeader[$key] .= "(";
         // DWORD  biSize;
         $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);
         // LONG   biWidth;
         // The biHeight member specifies the combined
         // height of the XOR and AND masks.
         $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4);
         // LONG   biHeight;
         $BitmapInfoHeader[$key] .= "";
         // WORD   biPlanes;
         $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "";
         // wBitCount;
         $BitmapInfoHeader[$key] .= "";
         // DWORD  biCompression;
         $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);
         // DWORD  biSizeImage;
         $BitmapInfoHeader[$key] .= "";
         // LONG   biXPelsPerMeter;
         $BitmapInfoHeader[$key] .= "";
         // LONG   biYPelsPerMeter;
         $BitmapInfoHeader[$key] .= "";
         // DWORD  biClrUsed;
         $BitmapInfoHeader[$key] .= "";
         // DWORD  biClrImportant;
     }
     $icondata = "";
     // idReserved;   // Reserved (must be 0)
     $icondata .= "";
     // idType;       // Resource Type (1 for icons)
     $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);
     // idCount;      // How many images?
     $dwImageOffset = 6 + count($gd_image_array) * 16;
     foreach ($gd_image_array as $key => $gd_image) {
         // ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
         $icondata .= chr($ImageWidths[$key]);
         // bWidth;          // Width, in pixels, of the image
         $icondata .= chr($ImageHeights[$key]);
         // bHeight;         // Height, in pixels, of the image
         $icondata .= chr($totalcolors[$key]);
         // bColorCount;     // Number of colors in image (0 if >=8bpp)
         $icondata .= "";
         // bReserved;       // Reserved ( must be 0)
         $icondata .= "";
         // wPlanes;         // Color Planes
         $icondata .= chr($bpp[$key]) . "";
         // wBitCount;       // Bits per pixel
         $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
         $icondata .= phpthumb_functions::LittleEndian2String($dwBytesInRes, 4);
         // dwBytesInRes;    // How many bytes in this resource?
         $icondata .= phpthumb_functions::LittleEndian2String($dwImageOffset, 4);
         // dwImageOffset;   // Where in the file is this image?
         $dwImageOffset += strlen($BitmapInfoHeader[$key]);
         $dwImageOffset += strlen($icXOR[$key]);
         $dwImageOffset += strlen($icAND[$key]);
     }
     foreach ($gd_image_array as $key => $gd_image) {
         $icondata .= $BitmapInfoHeader[$key];
         $icondata .= $icXOR[$key];
         $icondata .= $icAND[$key];
     }
     return $icondata;
 }
Пример #14
0
 /**
  * Desaturates an image, id optional $shade variable = 0 then image will be grey scale, 1 = red, 2 = greem 3 = blue
  *
  * NOTE: By adjusting the weight array prior to desaturating the image you can split the channels of an image.
  *
  * @param integer $shade What colour to shade the image
  * @return boolean Whether it was sucessful
  * @access public
  */
 function desaturate($shade = 0)
 {
     if (!$this->im) {
         return false;
     }
     //convert o,age to 256 colours
     ImageTrueColorToPalette($this->im, 1, 256);
     //calculate total number of colours in palette
     $total = ImageColorsTotal($this->im);
     //for each colour make it grey
     for ($i = 0; $i < $total; $i++) {
         $old = ImageColorsForIndex($this->im, $i);
         //get correct colouring by performing a weighted average of the 3
         $grey = round(($this->gamma[0] * $old["red"] + $this->gamma[1] * $old["green"] + $this->gamma[2] * $old["blue"]) / 3);
         if ($shade == 1) {
             ImageColorSet($this->im, $i, $grey, 0, 0);
         } else {
             if ($shade == 2) {
                 ImageColorSet($this->im, $i, 0, $grey, 0);
             } else {
                 if ($shade == 3) {
                     ImageColorSet($this->im, $i, 0, 0, $grey);
                 } else {
                     ImageColorSet($this->im, $i, $grey, $grey, $grey);
                 }
             }
         }
     }
     return true;
 }
Пример #15
0
 /**
  * Creates the icon file for the function getIcon()
  *
  * @param string $iconfile Original unprocessed Icon file, relative path to PATH_typo3
  * @param string $mode Mode string, eg. "deleted" or "futuretiming" determining how the icon will look
  * @param integer $user The number of the fe_group record uid if applicable
  * @param boolean $protectSection Flag determines if the protected-section icon should be applied.
  * @param string $absFile Absolute path to file from which to create the icon.
  * @param string $iconFileName_stateTagged The filename that this icon should have had, basically [icon base name]_[flags].[extension] - used for part of temporary filename
  * @return string Filename relative to PATH_typo3
  * @access private
  */
 public static function makeIcon($iconfile, $mode, $user, $protectSection, $absFile, $iconFileName_stateTagged)
 {
     $iconFileName = 'icon_' . GeneralUtility::shortMD5($iconfile . '|' . $mode . '|-' . $user . '|' . $protectSection) . '_' . $iconFileName_stateTagged . '.' . ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png'] ? 'png' : 'gif');
     $mainpath = '../typo3temp/' . $iconFileName;
     $path = PATH_site . 'typo3temp/' . $iconFileName;
     if (file_exists(PATH_typo3 . 'icons/' . $iconFileName)) {
         // Returns if found in typo3/icons/
         return 'icons/' . $iconFileName;
     } elseif (file_exists($path)) {
         // Returns if found in ../typo3temp/icons/
         return $mainpath;
     } else {
         // Makes icon:
         if (file_exists($absFile)) {
             if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib']) {
                 // Create image pointer, if possible
                 $im = self::imagecreatefrom($absFile);
                 if ($im < 0) {
                     return $iconfile;
                 }
                 // Converting to gray scale, dimming the icon:
                 if ($mode == 'disabled' or $mode != 'futuretiming' && $mode != 'no_icon_found' && !(!$mode && $user)) {
                     $totalImageColors = ImageColorsTotal($im);
                     for ($c = 0; $c < $totalImageColors; $c++) {
                         $cols = ImageColorsForIndex($im, $c);
                         $newcol = round(($cols['red'] + $cols['green'] + $cols['blue']) / 3);
                         $lighten = $mode == 'disabled' ? 2.5 : 2;
                         $newcol = round(255 - (255 - $newcol) / $lighten);
                         ImageColorSet($im, $c, $newcol, $newcol, $newcol);
                     }
                 }
                 // Applying user icon, if there are access control on the item:
                 if ($user) {
                     if ($user < 100) {
                         // Apply user number only if lower than 100
                         $black = ImageColorAllocate($im, 0, 0, 0);
                         imagefilledrectangle($im, 0, 0, $user > 10 ? 9 : 5, 8, $black);
                         $white = ImageColorAllocate($im, 255, 255, 255);
                         imagestring($im, 1, 1, 1, $user, $white);
                     }
                     $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_group.gif');
                     if ($ol_im < 0) {
                         return $iconfile;
                     }
                     self::imagecopyresized($im, $ol_im, 0, 0, 0, 0, imagesx($ol_im), imagesy($ol_im), imagesx($ol_im), imagesy($ol_im));
                 }
                 // Applying overlay based on mode:
                 if ($mode) {
                     unset($ol_im);
                     switch ($mode) {
                         case 'deleted':
                             $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_deleted.gif');
                             break;
                         case 'futuretiming':
                             $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_timing.gif');
                             break;
                         case 'timing':
                             $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_timing.gif');
                             break;
                         case 'hiddentiming':
                             $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_hidden_timing.gif');
                             break;
                         case 'no_icon_found':
                             $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_no_icon_found.gif');
                             break;
                         case 'disabled':
                             // is already greyed - nothing more
                             $ol_im = 0;
                             break;
                         case 'hidden':
                         default:
                             $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_hidden.gif');
                     }
                     if ($ol_im < 0) {
                         return $iconfile;
                     }
                     if ($ol_im) {
                         self::imagecopyresized($im, $ol_im, 0, 0, 0, 0, imagesx($ol_im), imagesy($ol_im), imagesx($ol_im), imagesy($ol_im));
                     }
                 }
                 // Protect-section icon:
                 if ($protectSection) {
                     $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'gfx/overlay_sub5.gif');
                     if ($ol_im < 0) {
                         return $iconfile;
                     }
                     self::imagecopyresized($im, $ol_im, 0, 0, 0, 0, imagesx($ol_im), imagesy($ol_im), imagesx($ol_im), imagesy($ol_im));
                 }
                 // Create the image as file, destroy GD image and return:
                 @self::imagemake($im, $path);
                 GeneralUtility::gif_compress($path, 'IM');
                 ImageDestroy($im);
                 return $mainpath;
             } else {
                 return $iconfile;
             }
         } else {
             return $GLOBALS['BACK_PATH'] . 'gfx/fileicons/default.gif';
         }
     }
 }
Пример #16
0
 /**
  * From: https://stackoverflow.com/questions/4590441/php-thumbnail-image-resizing-with-proportions
  */
 function resize(&$img, $size)
 {
     if (!is_numeric($size)) {
         $size = explode('x', $size);
     }
     if (is_array($size)) {
         $maxwidth = $size[0];
         $maxheight = $size[1];
     } else {
         if ($size) {
             $maxwidth = $size;
             $maxheight = $size;
         }
     }
     $width = imagesx($img);
     $height = imagesy($img);
     if (!ALLOW_BLOATING) {
         if ($maxwidth > $width) {
             $maxwidth = $width;
         }
         if ($maxheight > $height) {
             $maxheight = $height;
         }
     }
     if ($height > $width) {
         $ratio = $maxheight / $height;
         $newheight = $maxheight;
         $newwidth = $width * $ratio;
     } else {
         $ratio = $maxwidth / $width;
         $newwidth = $maxwidth;
         $newheight = $height * $ratio;
     }
     $newimg = imagecreatetruecolor($newwidth, $newheight);
     $palsize = ImageColorsTotal($img);
     for ($i = 0; $i < $palsize; $i++) {
         $colors = ImageColorsForIndex($img, $i);
         ImageColorAllocate($newimg, $colors['red'], $colors['green'], $colors['blue']);
     }
     imagefill($newimg, 0, 0, IMG_COLOR_TRANSPARENT);
     imagesavealpha($newimg, true);
     imagealphablending($newimg, true);
     imagecopyresampled($newimg, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
     $img = $newimg;
 }
Пример #17
0
 /**
  * @param $dst_img
  * @param $src_img
  * @param $dst_x
  * @param $dst_y
  * @param $src_x
  * @param $src_y
  * @param $dst_w
  * @param $dst_h
  * @param $src_w
  * @param $src_h
  */
 function ImageCopyResampleBicubic(&$dst_img, &$src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
 {
     $palsize = ImageColorsTotal($src_img);
     for ($i = 0; $i < $palsize; $i++) {
         // get palette.
         $colors = ImageColorsForIndex($src_img, $i);
         ImageColorAllocate($dst_img, $colors['red'], $colors['green'], $colors['blue']);
     }
     $scaleX = ($src_w - 1) / $dst_w;
     $scaleY = ($src_h - 1) / $dst_h;
     $scaleX2 = (int) ($scaleX / 2);
     $scaleY2 = (int) ($scaleY / 2);
     for ($j = $src_y; $j < $dst_h; $j++) {
         $sY = (int) ($j * $scaleY);
         $y13 = $sY + $scaleY2;
         for ($i = $src_x; $i < $dst_w; $i++) {
             $sX = (int) ($i * $scaleX);
             $x34 = $sX + $scaleX2;
             $color1 = ImageColorsForIndex($src_img, ImageColorAt($src_img, $sX, $y13));
             $color2 = ImageColorsForIndex($src_img, ImageColorAt($src_img, $sX, $sY));
             $color3 = ImageColorsForIndex($src_img, ImageColorAt($src_img, $x34, $y13));
             $color4 = ImageColorsForIndex($src_img, ImageColorAt($src_img, $x34, $sY));
             $red = ($color1['red'] + $color2['red'] + $color3['red'] + $color4['red']) / 4;
             $green = ($color1['green'] + $color2['green'] + $color3['green'] + $color4['green']) / 4;
             $blue = ($color1['blue'] + $color2['blue'] + $color3['blue'] + $color4['blue']) / 4;
             ImageSetPixel($dst_img, $i + $dst_x - $src_x, $j + $dst_y - $src_y, ImageColorClosest($dst_img, $red, $green, $blue));
         }
     }
 }
Пример #18
-1
 function loadImageFromFile($imageInfo)
 {
     $_result = 0;
     $filelocation = $imageInfo['file_location'];
     //$filelocation = dirname($this->_filename).'/'.$filelocation;
     switch ($imageInfo['type']) {
         case 1:
             $_result = @imagecreatefromgif($filelocation);
             break;
         case 2:
             $_result = @imagecreatefromjpeg($filelocation);
             break;
         case 3:
             $_result = @imagecreatefrompng($filelocation);
             break;
         case 4:
             $_result = @imagecreatefromswf($filelocation);
             break;
         case 6:
             $_result = @imagecreatefromwbmp($filelocation);
             break;
         case 15:
             $_result = @imagecreatefromxbm($filelocation);
             break;
     }
     $_colorCount = ImageColorsTotal($_result);
     //$this->log->info[] = 'testing image: '. basename($filelocation) . ' colors: '.$_colorCount .
     //" size:[{$imageInfo['width']}x{$imageInfo['height']}]\n";
     if ($this->_maxColors < $_colorCount) {
         $this->_maxColors = $_colorCount;
     }
     if ($_colorCount == 0) {
         $this->_trueColor = true;
     }
     if (!$_result) {
         die("ERROR: Can not open file: {$filelocation}\n");
     }
     return $_result;
 }