当前位置: 首页>>代码示例>>PHP>>正文


PHP ImageInterlace函数代码示例

本文整理汇总了PHP中ImageInterlace函数的典型用法代码示例。如果您正苦于以下问题:PHP ImageInterlace函数的具体用法?PHP ImageInterlace怎么用?PHP ImageInterlace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ImageInterlace函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: TextToImage

function TextToImage($text, $separate_line_after_chars = 40, $size = 24, $rotate = 0, $padding = 2, $transparent = true, $color = array('red' => 0, 'grn' => 0, 'blu' => 0), $bg_color = array('red' => 255, 'grn' => 255, 'blu' => 255))
{
    $amount_of_lines = ceil(strlen($text) / $separate_line_after_chars);
    $x = explode("\n", $text);
    $final = '';
    foreach ($x as $key => $value) {
        $returnes = '';
        do {
            $first_part = mb_substr($value, 0, $separate_line_after_chars, 'utf-8');
            $value = "\n" . mb_substr($value, $separate_line_after_chars, null, 'utf-8');
            $returnes .= $first_part;
        } while (mb_strlen($value, 'utf-8') > $separate_line_after_chars);
        $final .= $returnes . "\n";
    }
    $text = $final;
    $width = $height = $offset_x = $offset_y = 0;
    $font = $_SERVER['DOCUMENT_ROOT'] . '/assets/css/journal.ttf';
    // get the font height.
    $bounds = ImageTTFBBox($size, $rotate, $font, "W");
    if ($rotate < 0) {
        $font_height = abs($bounds[7] - $bounds[1]);
    } elseif ($rotate > 0) {
        $font_height = abs($bounds[1] - $bounds[7]);
    } else {
        $font_height = abs($bounds[7] - $bounds[1]);
    }
    // determine bounding box.
    $bounds = ImageTTFBBox($size, $rotate, $font, $text);
    if ($rotate < 0) {
        $width = abs($bounds[4] - $bounds[0]);
        $height = abs($bounds[3] - $bounds[7]);
        $offset_y = $font_height;
        $offset_x = 0;
    } elseif ($rotate > 0) {
        $width = abs($bounds[2] - $bounds[6]);
        $height = abs($bounds[1] - $bounds[5]);
        $offset_y = abs($bounds[7] - $bounds[5]) + $font_height;
        $offset_x = abs($bounds[0] - $bounds[6]);
    } else {
        $width = abs($bounds[4] - $bounds[6]);
        $height = abs($bounds[7] - $bounds[1]);
        $offset_y = $font_height;
        $offset_x = 0;
    }
    $image = imagecreate($width + $padding * 2 + 1, $height + $padding * 2 + 1);
    $background = ImageColorAllocate($image, $bg_color['red'], $bg_color['grn'], $bg_color['blu']);
    $foreground = ImageColorAllocate($image, $color['red'], $color['grn'], $color['blu']);
    if ($transparent) {
        ImageColorTransparent($image, $background);
    }
    ImageInterlace($image, true);
    // render the image
    ImageTTFText($image, $size, $rotate, $offset_x + $padding, $offset_y + $padding, $foreground, $font, $text);
    imagealphablending($image, true);
    imagesavealpha($image, true);
    // output PNG object.
    imagePNG($image, 'signature.png');
    imagedestroy($image);
}
开发者ID:kevwaddell,项目名称:tlw-echosign,代码行数:59,代码来源:text-to-img.php

示例2: draw

 function draw()
 {
     $width = 0;
     $height = 0;
     $offset_x = 0;
     $offset_y = 0;
     $bounds = array();
     $image = "";
     // get the font height.
     $bounds = ImageTTFBBox($this->size, $this->rot, $this->font, "W");
     if ($this->rot < 0) {
         $font_height = abs($bounds[7] - $bounds[1]);
     } else {
         if ($this->rot > 0) {
             $font_height = abs($bounds[1] - $bounds[7]);
         } else {
             $font_height = abs($bounds[7] - $bounds[1]);
         }
     }
     // determine bounding box.
     $bounds = ImageTTFBBox($this->size, $this->rot, $this->font, $this->msg);
     if ($this->rot < 0) {
         $width = abs($bounds[4] - $bounds[0]);
         $height = abs($bounds[3] - $bounds[7]);
         $offset_y = $font_height;
         $offset_x = 0;
     } else {
         if ($this->rot > 0) {
             $width = abs($bounds[2] - $bounds[6]);
             $height = abs($bounds[1] - $bounds[5]);
             $offset_y = abs($bounds[7] - $bounds[5]) + $font_height;
             $offset_x = abs($bounds[0] - $bounds[6]);
         } else {
             $width = abs($bounds[4] - $bounds[6]);
             $height = abs($bounds[7] - $bounds[1]);
             $offset_y = $font_height;
             $offset_x = 0;
         }
     }
     $image = imagecreate($width + $this->padX * 2 + 1, $height + $this->padY * 2 + 1);
     $background = ImageColorAllocate($image, $this->bg_red, $this->bg_grn, $this->bg_blu);
     $foreground = ImageColorAllocate($image, $this->red, $this->grn, $this->blu);
     if ($this->transparent) {
         ImageColorTransparent($image, $background);
     }
     ImageInterlace($image, false);
     // render the image
     ImageTTFText($image, $this->size, $this->rot, $offset_x + $this->padX, $offset_y + $this->padY, $foreground, $this->font, $this->msg);
     // output PNG object.
     imagePNG($image);
 }
开发者ID:pankajsinghjarial,项目名称:SYLC-AMERICAN,代码行数:51,代码来源:toImage.php

示例3: NewImage

 function NewImage($width, $height, $interlace = NULL)
 {
     $this->width = $width;
     $this->height = $height;
     $this->SetFont();
     if (function_exists("imagecreatetruecolor")) {
         $this->img = imagecreatetruecolor($this->width, $this->height);
     } else {
         $this->img = imagecreate($this->width, $this->height);
     }
     if (!$this->img) {
         $this->img = imagecreate($this->width, $this->height);
     }
     if (!$this->img) {
         return t('Unable to Initialize new GD image stream');
     }
     ImageInterlace($this->img, $interlace);
 }
开发者ID:eistr2n,项目名称:lansuite,代码行数:18,代码来源:class_gd.php

示例4: OutputThumbnail

 function OutputThumbnail()
 {
     if (!is_resource($this->gdimg_output)) {
         $this->DebugMessage('OutputThumbnail() failed because !is_resource($this->gdimg_output)', __FILE__, __LINE__);
         return false;
     }
     if (headers_sent()) {
         return $this->ErrorImage('OutputThumbnail() failed - headers already sent');
         exit;
     }
     if (!empty($this->down)) {
         $downloadfilename = ereg_replace('[/\\:\\*\\?"<>|]', '_', $this->down);
         if (phpthumb_functions::version_compare_replacement(phpversion(), '4.1.0', '>=')) {
             $downloadfilename = trim($downloadfilename, '.');
         }
         if ($downloadfilename != $this->down) {
             $this->DebugMessage('renaming output file for "down" from "' . $this->down . '" to "' . $downloadfilename . '"', __FILE__, __LINE__);
         }
         if ($downloadfilename) {
             header('Content-Disposition: attachment; filename="' . $downloadfilename . '"');
         } else {
             $this->DebugMessage('failed to send Content-Disposition header because $downloadfilename is empty', __FILE__, __LINE__);
         }
     }
     ImageInterlace($this->gdimg_output, intval($this->config_output_interlace));
     $ImageOutFunction = 'image' . $this->thumbnailFormat;
     switch ($this->thumbnailFormat) {
         case 'jpeg':
             header('Content-type: image/' . $this->thumbnailFormat);
             @$ImageOutFunction($this->gdimg_output, '', $this->thumbnailQuality);
             break;
         case 'png':
         case 'gif':
             header('Content-type: image/' . $this->thumbnailFormat);
             @$ImageOutFunction($this->gdimg_output);
             break;
     }
     ImageDestroy($this->gdimg_output);
     return true;
 }
开发者ID:BackupTheBerlios,项目名称:milaninegw-svn,代码行数:40,代码来源:phpthumb.class.php

示例5: generateImage

function generateImage($source_file, $cache_file, $resolution)
{
    global $sharpen, $jpg_quality;
    $extension = strtolower(pathinfo($source_file, PATHINFO_EXTENSION));
    // Check the image dimensions
    $dimensions = GetImageSize($source_file);
    $width = $dimensions[0];
    $height = $dimensions[1];
    // Do we need to downscale the image?
    if ($width <= $resolution) {
        // no, because the width of the source image is already less than the client width
        return $source_file;
    }
    // We need to resize the source image to the width of the resolution breakpoint we're working with
    $ratio = $height / $width;
    $new_width = $resolution;
    $new_height = ceil($new_width * $ratio);
    $dst = ImageCreateTrueColor($new_width, $new_height);
    // re-sized image
    switch ($extension) {
        case 'png':
            $src = @ImageCreateFromPng($source_file);
            // original image
            break;
        case 'gif':
            $src = @ImageCreateFromGif($source_file);
            // original image
            break;
        default:
            $src = @ImageCreateFromJpeg($source_file);
            // original image
            ImageInterlace($dst, true);
            // Enable interlancing (progressive JPG, smaller size file)
            break;
    }
    if ($extension == 'png') {
        imagealphablending($dst, false);
        imagesavealpha($dst, true);
        $transparent = imagecolorallocatealpha($dst, 255, 255, 255, 127);
        imagefilledrectangle($dst, 0, 0, $new_width, $new_height, $transparent);
    }
    ImageCopyResampled($dst, $src, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
    // do the resize in memory
    ImageDestroy($src);
    // sharpen the image?
    // NOTE: requires PHP compiled with the bundled version of GD (see http://php.net/manual/en/function.imageconvolution.php)
    if ($sharpen == TRUE && function_exists('imageconvolution')) {
        $intSharpness = findSharp($width, $new_width);
        $arrMatrix = array(array(-1, -2, -1), array(-2, $intSharpness + 12, -2), array(-1, -2, -1));
        imageconvolution($dst, $arrMatrix, $intSharpness, 0);
    }
    $cache_dir = dirname($cache_file);
    // does the directory exist already?
    if (!is_dir($cache_dir)) {
        if (!mkdir($cache_dir, 0755, true)) {
            // check again if it really doesn't exist to protect against race conditions
            if (!is_dir($cache_dir)) {
                // uh-oh, failed to make that directory
                ImageDestroy($dst);
                sendErrorImage("Failed to create cache directory: {$cache_dir}");
            }
        }
    }
    if (!is_writable($cache_dir)) {
        sendErrorImage("The cache directory is not writable: {$cache_dir}");
    }
    // save the new file in the appropriate path, and send a version to the browser
    switch ($extension) {
        case 'png':
            $gotSaved = ImagePng($dst, $cache_file);
            break;
        case 'gif':
            $gotSaved = ImageGif($dst, $cache_file);
            break;
        default:
            $gotSaved = ImageJpeg($dst, $cache_file, $jpg_quality);
            break;
    }
    ImageDestroy($dst);
    if (!$gotSaved && !file_exists($cache_file)) {
        sendErrorImage("Failed to create image: {$cache_file}");
    }
    return $cache_file;
}
开发者ID:vishalishere,项目名称:accessyoutube,代码行数:84,代码来源:adaptive-images.php

示例6: OutputThumbnail

 function OutputThumbnail()
 {
     $this->purgeTempFiles();
     if (!$this->useRawIMoutput && !is_resource($this->gdimg_output)) {
         $this->DebugMessage('OutputThumbnail() failed because !is_resource($this->gdimg_output)', __FILE__, __LINE__);
         return false;
     }
     if (headers_sent()) {
         return $this->ErrorImage('OutputThumbnail() failed - headers already sent');
         exit;
     }
     $downloadfilename = phpthumb_functions::SanitizeFilename(is_string($this->sia) ? $this->sia : ($this->down ? $this->down : 'phpThumb_generated_thumbnail' . '.' . $this->thumbnailFormat));
     $this->DebugMessage('Content-Disposition header filename set to "' . $downloadfilename . '"', __FILE__, __LINE__);
     if ($downloadfilename) {
         header('Content-Disposition: ' . ($this->down ? 'attachment' : 'inline') . '; filename="' . $downloadfilename . '"');
     } else {
         $this->DebugMessage('failed to send Content-Disposition header because $downloadfilename is empty', __FILE__, __LINE__);
     }
     if ($this->useRawIMoutput) {
         header('Content-Type: ' . phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat));
         echo $this->IMresizedData;
     } else {
         $this->DebugMessage('ImageInterlace($this->gdimg_output, ' . intval($this->config_output_interlace) . ')', __FILE__, __LINE__);
         ImageInterlace($this->gdimg_output, intval($this->config_output_interlace));
         switch ($this->thumbnailFormat) {
             case 'jpeg':
                 header('Content-Type: ' . phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat));
                 $ImageOutFunction = 'image' . $this->thumbnailFormat;
                 @$ImageOutFunction($this->gdimg_output, '', $this->thumbnailQuality);
                 break;
             case 'png':
             case 'gif':
                 header('Content-Type: ' . phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat));
                 $ImageOutFunction = 'image' . $this->thumbnailFormat;
                 @$ImageOutFunction($this->gdimg_output);
                 break;
             case 'bmp':
                 if (!@(include_once dirname(__FILE__) . '/phpthumb.bmp.php')) {
                     $this->DebugMessage('Error including "' . dirname(__FILE__) . '/phpthumb.bmp.php" which is required for BMP format output', __FILE__, __LINE__);
                     return false;
                 }
                 $phpthumb_bmp = new phpthumb_bmp();
                 if (is_object($phpthumb_bmp)) {
                     $bmp_data = $phpthumb_bmp->GD2BMPstring($this->gdimg_output);
                     unset($phpthumb_bmp);
                     if (!$bmp_data) {
                         $this->DebugMessage('$phpthumb_bmp->GD2BMPstring() failed', __FILE__, __LINE__);
                         return false;
                     }
                     header('Content-Type: ' . phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat));
                     echo $bmp_data;
                 } else {
                     $this->DebugMessage('new phpthumb_bmp() failed', __FILE__, __LINE__);
                     return false;
                 }
                 break;
             case 'ico':
                 if (!@(include_once dirname(__FILE__) . '/phpthumb.ico.php')) {
                     $this->DebugMessage('Error including "' . dirname(__FILE__) . '/phpthumb.ico.php" which is required for ICO format output', __FILE__, __LINE__);
                     return false;
                 }
                 $phpthumb_ico = new phpthumb_ico();
                 if (is_object($phpthumb_ico)) {
                     $arrayOfOutputImages = array($this->gdimg_output);
                     $ico_data = $phpthumb_ico->GD2ICOstring($arrayOfOutputImages);
                     unset($phpthumb_ico);
                     if (!$ico_data) {
                         $this->DebugMessage('$phpthumb_ico->GD2ICOstring() failed', __FILE__, __LINE__);
                         return false;
                     }
                     header('Content-Type: ' . phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat));
                     echo $ico_data;
                 } else {
                     $this->DebugMessage('new phpthumb_ico() failed', __FILE__, __LINE__);
                     return false;
                 }
                 break;
             default:
                 $this->DebugMessage('OutputThumbnail failed because $this->thumbnailFormat "' . $this->thumbnailFormat . '" is not valid', __FILE__, __LINE__);
                 return false;
                 break;
         }
     }
     return true;
 }
开发者ID:notzen,项目名称:exponent-cms,代码行数:85,代码来源:phpthumb.class.php

示例7: OutputThumbnail

 function OutputThumbnail()
 {
     if (headers_sent()) {
         die('OutputThumbnail() failed - headers already sent');
     }
     $ImageOutFunction = 'image' . $this->thumbnailFormat;
     ImageInterlace($this->gdimg_output, 1);
     switch ($this->thumbnailFormat) {
         case 'jpeg':
             header('Content-type: image/' . $this->thumbnailFormat);
             @$ImageOutFunction($this->gdimg_output, '', $this->thumbnailQuality);
             break;
         case 'png':
         case 'gif':
             header('Content-type: image/' . $this->thumbnailFormat);
             @$ImageOutFunction($this->gdimg_output);
             break;
     }
     ImageDestroy($this->gdimg_output);
     return true;
 }
开发者ID:BackupTheBerlios,项目名称:ydframework-svn,代码行数:21,代码来源:phpthumb.class.php

示例8: OutputThumbnail

 function OutputThumbnail()
 {
     if (!is_resource($this->gdimg_output)) {
         $this->DebugMessage('OutputThumbnail() failed because !is_resource($this->gdimg_output)', __FILE__, __LINE__);
         return false;
     }
     if (headers_sent()) {
         return $this->ErrorImage('OutputThumbnail() failed - headers already sent');
         exit;
     }
     if ($this->down) {
         $downloadfilename = ereg_replace('[/\\:\\*\\?"<>|]', '_', $this->down);
         if (phpthumb_functions::version_compare_replacement(phpversion(), '4.1.0', '>=')) {
             $downloadfilename = trim($downloadfilename, '.');
         }
         if ($downloadfilename != $this->down) {
             $this->DebugMessage('renaming output file for "down" from "' . $this->down . '" to "' . $downloadfilename . '"', __FILE__, __LINE__);
         }
         if ($downloadfilename) {
             header('Content-Disposition: attachment; filename="' . $downloadfilename . '"');
         } else {
             $this->DebugMessage('failed to send Content-Disposition header because $downloadfilename is empty', __FILE__, __LINE__);
         }
     }
     $useRawIMoutput = true;
     if (@$this->getimagesizeinfo[2] != 1 || $this->thumbnailFormat != 'gif') {
         $this->DebugMessage('RenderToFile skipping $useRawIMoutput because of $this->getimagesizeinfo[2] (' . @$this->getimagesizeinfo[2] . ') or $this->thumbnailFormat (' . $this->thumbnailFormat . ')', __FILE__, __LINE__);
         $useRawIMoutput = false;
     } else {
         $UnAllowedParameters = array('sx', 'sy', 'sw', 'sh', 'xto', 'ra', 'ar', 'bg', 'bc', 'fltr');
         foreach ($UnAllowedParameters as $parameter) {
             if ($this->{$parameter}) {
                 $useRawIMoutput = false;
                 break;
             }
         }
     }
     if ($useRawIMoutput) {
         header('Content-Type: image/' . $this->thumbnailFormat);
         echo $this->IMresizedData;
     } else {
         ImageInterlace($this->gdimg_output, intval($this->config_output_interlace));
         switch ($this->thumbnailFormat) {
             case 'jpeg':
                 header('Content-Type: image/' . $this->thumbnailFormat);
                 $ImageOutFunction = 'image' . $this->thumbnailFormat;
                 @$ImageOutFunction($this->gdimg_output, '', $this->thumbnailQuality);
                 break;
             case 'png':
             case 'gif':
                 header('Content-Type: image/' . $this->thumbnailFormat);
                 $ImageOutFunction = 'image' . $this->thumbnailFormat;
                 @$ImageOutFunction($this->gdimg_output);
                 break;
             default:
                 $this->DebugMessage('OutputThumbnail failed because $this->thumbnailFormat "' . $this->thumbnailFormat . '" is not valid', __FILE__, __LINE__);
                 return false;
                 break;
         }
         ImageDestroy($this->gdimg_output);
     }
     return true;
 }
开发者ID:alanhaggai,项目名称:plogger,代码行数:63,代码来源:phpthumb.class.php

示例9: buildThumbnail


//.........这里部分代码省略.........
         case "im":
             //use ImageMagick v5.x
             $cmd = '"' . $this->config->pathto_convert . '"';
             if ($this->forceSize) {
                 $cmd .= " -crop {$this->cropWidth}x{$this->cropHeight}+{$this->cropX}+{$this->cropY}";
             }
             $cmd .= " -geometry {$this->thumbWidth}x{$this->thumbHeight}";
             if ($this->image->type == 2) {
                 $cmd .= " -quality " . $this->config->thumbnail_quality;
             }
             if ($this->config->progressive_thumbs) {
                 $cmd .= " -interlace Plane";
             }
             if ($this->config->remove_jpeg_profile) {
                 $cmd .= ' +profile "*"';
             }
             $cmd .= ' ' . escapeshellarg($this->imagePath) . ' ' . escapeshellarg($this->thumbPath);
             exec($cmd);
             break;
         case "im6":
             //use ImageMagick v6.x
             $cmd = '"' . $this->config->pathto_convert . '"';
             $cmd .= ' ' . escapeshellarg($this->imagePath);
             if ($this->config->progressive_thumbs) {
                 $cmd .= " -interlace Plane";
             }
             if ($this->image->type == 2) {
                 $cmd .= " -quality " . $this->config->thumbnail_quality;
             }
             if ($this->forceSize) {
                 $cmd .= " -crop {$this->cropWidth}x{$this->cropHeight}+{$this->cropX}+{$this->cropY}";
             }
             $cmd .= " -resize {$this->thumbWidth}x{$this->thumbHeight}";
             if ($this->config->remove_jpeg_profile) {
                 $cmd .= ' +profile "*"';
             }
             $cmd .= ' ' . escapeshellarg($this->thumbPath);
             exec($cmd);
             break;
         case "gd2":
         case "gd1":
         default:
             //use GD by default
             //read in image as appropriate type
             switch ($this->image->type) {
                 case 1:
                     $image = ImageCreateFromGIF($this->imagePath);
                     break;
                 case 3:
                     $image = ImageCreateFromPNG($this->imagePath);
                     break;
                 case 2:
                 default:
                     $image = ImageCreateFromJPEG($this->imagePath);
                     break;
             }
             if ($image) {
                 switch ($this->config->thumbnail_software) {
                     case "gd2":
                         //create blank truecolor image
                         $thumb = ImageCreateTrueColor($this->thumbWidth, $this->thumbHeight);
                         //resize image with resampling
                         ImageCopyResampled($thumb, $image, 0, 0, $cropX, $cropY, $this->thumbWidth, $this->thumbHeight, $this->cropWidth, $this->cropHeight);
                         break;
                     case "gd1":
                     default:
                         //create blank 256 color image
                         $thumb = ImageCreate($this->thumbWidth, $this->thumbHeight);
                         //resize image
                         ImageCopyResized($thumb, $image, 0, 0, $cropX, $cropY, $this->thumbWidth, $this->thumbHeight, $this->cropWidth, $this->cropHeight);
                         break;
                 }
             }
             /*else {
                 $thumb = ImageCreate($this->thumbWidth, $this->thumbHeight);
                 $bg = ImageColorAllocate($thumb, 255, 255, 255);
                 $text = ImageColorAllocate($thumb, 255, 0, 0);
                 ImageString($thumb, 1, 0, 0, "Cannot load source image", $text);
               }*/
             //set image interlacing
             @ImageInterlace($thumb, $this->config->progressive_thumbs);
             //output image of appropriate type
             switch ($this->image->type) {
                 case 1:
                     //GIF images are saved as PNG
                 //GIF images are saved as PNG
                 case 3:
                     ImagePNG($thumb, $this->thumbPath);
                     break;
                 case 2:
                 default:
                     ImageJPEG($thumb, $this->thumbPath, $this->config->thumbnail_quality);
                     break;
             }
             @ImageDestroy($image);
             @ImageDestroy($thumb);
     }
     //set file permissions on newly created thumbnail
     @chmod($this->thumbPath, octdec($this->config->file_mode));
 }
开发者ID:kyroskoh,项目名称:singapore-1,代码行数:101,代码来源:thumbnail.class.php

示例10: complete

 function complete()
 {
     ImageInterlace($this->im, 1);
     ImagePNG($this->im);
     ImageDestroy($this->im);
 }
开发者ID:scoder,项目名称:benchmarksgame,代码行数:6,代码来源:lib_chart.php

示例11: resize_image

 function resize_image($image, $crop = false, $size = null, $addWatermark = false)
 {
     $file = $image;
     $image = ImageCreateFromString(file_get_contents($image));
     if (is_resource($image) === true) {
         $x = 0;
         $y = 0;
         $width = imagesx($image);
         $height = imagesy($image);
         /*
          CROP (Aspect Ratio) Section-----------------------------------------------------------------
         */
         if ($crop == false) {
             $crop = array($width, $height);
         } else {
             $crop = array_filter(explode(':', $crop));
             // $crop = explode(':', $crop); print_r($crop);
             //detect if width and height ratio is "auto"
             if ($crop[1] == 'auto' && $crop[0] === 'auto') {
                 $crop = array($width, $height);
             }
             //detect if height ratio is "auto"
             if ($crop[1] == 'auto') {
                 $crop[1] = intval($crop[0] * $height / $width);
             }
             //end
             //detect if width ratio is "auto"
             if ($crop[0] == 'auto') {
                 $crop[0] = intval($crop[1] * $width / $height);
             }
             //end
             if (empty($crop) === true) {
                 $crop = array($width, $height);
             } else {
                 if (empty($crop[0]) == true || is_numeric($crop[0]) == false) {
                     $crop[0] = $crop[1];
                 } else {
                     if (empty($crop[1]) == true || is_numeric($crop[1]) == false) {
                         $crop[1] = $crop[0];
                     }
                 }
             }
             $ratio = array(0 => $width / $height, 1 => $crop[0] / $crop[1]);
             if ($ratio[0] > $ratio[1]) {
                 $width = $height * $ratio[1];
                 $x = (imagesx($image) - $width) / 2;
             } else {
                 if ($ratio[0] < $ratio[1]) {
                     $height = $width / $ratio[1];
                     $y = (imagesy($image) - $height) / 2;
                 }
             }
         }
         /*
          Resize Section-------------------------------------------------------------------------------
         */
         if (is_null($size) === true) {
             $size = array($width, $height);
             $indexedSize = $width . "x" . $height;
         } else {
             $indexedSize = $size;
             $size = array_filter(explode('x', $size));
             if (empty($size) === true) {
                 $size = array(imagesx($image), imagesy($image));
             } else {
                 if (empty($size[0]) === true || is_numeric($size[0]) === false) {
                     $size[0] = round($size[1] * $width / $height);
                 } else {
                     if (empty($size[1]) === true || is_numeric($size[1]) === false) {
                         $size[1] = round($size[0] * $height / $width);
                     }
                 }
             }
         }
         $result = ImageCreateTrueColor($size[0], $size[1]);
         //get file ext and remove it
         $filename = explode('.', $file);
         $ext = "." . end($filename);
         array_pop($filename);
         $filename = implode('.', $filename);
         //insert image resized dimension into image name
         $filename = explode("/", $filename);
         #$img_name = implode("x", $size) . '-' . end($filename);
         $img_name = $indexedSize . '-' . end($filename);
         array_pop($filename);
         $filepath = implode('/', $filename);
         $filename = $filepath . '/' . $img_name . $ext;
         if (is_file($filename)) {
             unlink($filename);
         }
         #imagejpeg($result, $filename, 100);
         if (is_resource($result) === true) {
             ImageSaveAlpha($result, true);
             ImageAlphaBlending($result, true);
             ImageFill($result, 0, 0, ImageColorAllocate($result, 255, 255, 255));
             //ImageCopyResampled($result, $image, 0, -10, $x, $y, $size[0], $size[1], $width, $height); // upload axis y start at -20
             ImageCopyResampled($result, $image, 0, 0, $x, $y, $size[0], $size[1], $width, $height);
             // upload axis y start at -20
             ImageInterlace($result, true);
             ImageJPEG($result, $filename, 100);
//.........这里部分代码省略.........
开发者ID:cyberorca,项目名称:dfp-api,代码行数:101,代码来源:upload.php

示例12: edit_image


//.........这里部分代码省略.........
             		  // DEBIAN EDGE FIX => crashes at imagefill, so use old Method
             		  if($GDInfo["GD Version"] === '2.0 or higher' && !function_exists("imagerotate")){
             		  // set black to transparent!
             		  if($output_format === 'gif' || $output_format === 'png'){ // transparency with gifs
             		  imagecolortransparent($_output_gdimg, imagecolorallocate($_output_gdimg, 0, 0, 0)); // set this color to transparent - done
             		  }
             		  } else {
             		 */
             // preserve transparency of png and gif images:
             switch ($output_format) {
                 case "gif":
                     $colorTransparent = imagecolortransparent($_gdimg);
                     imagepalettecopy($_gdimg, $_output_gdimg);
                     imagefill($_output_gdimg, 0, 0, $colorTransparent);
                     imagecolortransparent($_output_gdimg, $colorTransparent);
                     imagetruecolortopalette($_output_gdimg, true, 256);
                     break;
                 case "png":
                     imagealphablending($_output_gdimg, false);
                     //$transparent = imagecolorallocatealpha($_output_gdimg, 0, 0, 0, 127);
                     $transparent = imagecolorallocatealpha($_output_gdimg, 255, 255, 255, 127);
                     imagefill($_output_gdimg, 0, 0, $transparent);
                     imagesavealpha($_output_gdimg, true);
                     break;
                 default:
             }
             //}
             // Resize image
             //if($_outsize["width"] == "1")
             if ($fitinside && $keep_aspect_ratio && $width && $height) {
                 $wratio = $width / $_width;
                 $hratio = $height / $_height;
                 $ratio = max($width / $_width, $height / $_height);
                 $h = $height / $ratio;
                 $w = $width / $ratio;
                 if ($wratio < $hratio) {
                     $x = ($_width - $width / $ratio) / 2;
                     $y = 0;
                 } else {
                     $x = 0;
                     $y = ($_height - $height / $ratio) / 2;
                 }
                 // Set thumbnail focus point -ah2015
                 if (true) {
                     echo '<script>console.log("TX:"+' . $x . ', "TY:"+' . $y . ', "OWidth:"+' . $_width . ', "TWidth"+' . $width . ', "OHeight:"+' . $_height . ', "THeight"+' . $height . ');</script>';
                     $x_focus = $crop_x;
                     // von -1.0 bis 1.0
                     $y_focus = $crop_y;
                     // von -1.0 bis 1.0
                     $x = $x + $x * $x_focus;
                     $y = $y + $y * $y_focus;
                 }
                 $_image_resize_function($_output_gdimg, $_gdimg, 0, 0, $x, $y, $width, $height, $w, $h);
             } else {
                 $_image_resize_function($_output_gdimg, $_gdimg, 0, 0, 0, 0, $_outsize["width"], $_outsize["height"], $_width, $_height);
             }
             // PHP 4.4.1 GDLIB-Bug/Safemode - Workarround
             if ($output_filename != "" && file_exists($output_filename)) {
                 touch($output_filename);
             }
             ImageInterlace($_output_gdimg, $interlace ? 1 : 0);
             switch ($output_format) {
                 case 'jpg':
                     // Output to a filename or directly
                     if ($output_filename != "") {
                         $_gdimg = imagejpeg($_output_gdimg, $output_filename, $output_quality);
                         if ($_gdimg) {
                             $_gdimg = basename($output_filename);
                         }
                     } elseif ($_tempfilename = tempnam(TEMP_PATH, "")) {
                         imagejpeg($_output_gdimg, $_tempfilename, $output_quality);
                         $_gdimg = we_base_file::load($_tempfilename);
                         // As we read the temporary file we no longer need it
                         //unlink($_tempfilename);
                     }
                     break;
                 case 'png':
                 case 'gif':
                     // Set output function
                     $_image_out_function = 'image' . $output_format;
                     // Output to a filename or directly
                     if ($output_filename) {
                         $_gdimg = $_image_out_function($_output_gdimg, $output_filename);
                         if ($_gdimg) {
                             $_gdimg = basename($output_filename);
                         }
                     } elseif ($_tempfilename = tempnam(TEMP_PATH, "")) {
                         $_image_out_function($_output_gdimg, $_tempfilename);
                         $_gdimg = we_base_file::load($_tempfilename);
                         // As we read the temporary file we no longer need it
                         unlink($_tempfilename);
                     }
                     break;
             }
             ImageDestroy($_output_gdimg);
         }
         return isset($_gdimg) ? array($_gdimg, $_outsize["width"], $_outsize["height"]) : array(false, -1, -1);
     }
     return array(false, -1, -1);
 }
开发者ID:andreaswitt,项目名称:CMSwebEdition,代码行数:101,代码来源:we_base_imageEdit.class.php

示例13: constrain

 /**
  * SICWebImage::constrain() - a GD library-based crop and resize utility
  * function
  *
  * Props to Alix Axel and monowerker at <http://stackoverflow.com/questions/999250/php-gd-cropping-and-resizing-images>
  * for some nice packaging of the code to do this with only the GD library
  * functions.
  */
 function constrain($crop = null, $size = null)
 {
     $ret = NULL;
     if ($this->is_image() and (!is_null($crop) or !is_null($size))) {
         if (self::has_gd()) {
             $image = ImageCreateFromString($this->data());
             $data = NULL;
             $mimetype = NULL;
             if (is_resource($image) === true) {
                 $x = 0;
                 $y = 0;
                 $width = imagesx($image);
                 $height = imagesy($image);
                 /*
                 CROP (Aspect Ratio) Section
                 */
                 if (is_null($crop) === true) {
                     $crop = array($width, $height);
                 } else {
                     $crop = array_filter(explode(':', $crop));
                     if (empty($crop) === true) {
                         $crop = array($width, $height);
                     } else {
                         if (empty($crop[0]) === true || is_numeric($crop[0]) === false) {
                             $crop[0] = $crop[1];
                         } elseif (empty($crop[1]) === true || is_numeric($crop[1]) === false) {
                             $crop[1] = $crop[0];
                         }
                     }
                     $ratio = array(0 => $width / $height, 1 => $crop[0] / $crop[1]);
                     if ($ratio[0] > $ratio[1]) {
                         $width = $height * $ratio[1];
                         $x = (imagesx($image) - $width) / 2;
                     } elseif ($ratio[0] < $ratio[1]) {
                         $height = $width / $ratio[1];
                         $y = (imagesy($image) - $height) / 2;
                     }
                 }
                 /*
                 Resize Section
                 */
                 if (is_null($size) === true) {
                     $size = array($width, $height);
                 } else {
                     $size = array_filter(explode('x', $size));
                     if (empty($size) === true) {
                         $size = array(imagesx($image), imagesy($image));
                     } else {
                         if (empty($size[0]) === true || is_numeric($size[0]) === false) {
                             $size[0] = round($size[1] * $width / $height);
                         } elseif (empty($size[1]) === true || is_numeric($size[1]) === false) {
                             $size[1] = round($size[0] * $height / $width);
                         }
                     }
                 }
                 $result = ImageCreateTrueColor($size[0], $size[1]);
                 if (is_resource($result) === true) {
                     ImageSaveAlpha($result, true);
                     ImageAlphaBlending($result, true);
                     ImageFill($result, 0, 0, ImageColorAllocate($result, 255, 255, 255));
                     ImageCopyResampled($result, $image, 0, 0, $x, $y, $size[0], $size[1], $width, $height);
                     ImageInterlace($result, true);
                     ob_start();
                     // *sigh*
                     ImageJPEG($result, null, 90);
                     $mimetype = 'image/jpeg';
                     $data = ob_get_clean();
                     // *sigh*
                 }
             }
             // (is_resource($image) === true)
             $ret = array($data, $mimetype);
         }
         // function_exists('ImageCreateFromString')
         if (!is_null($ret) and !is_null($ret[0])) {
             $this->set_image($ret[0], $ret[1]);
         }
     }
     return $ret;
 }
开发者ID:dereks36,项目名称:FWP---SIC--Em,代码行数:88,代码来源:sicwebimage.class.php

示例14: _createTTFImage

 protected static function _createTTFImage($txt)
 {
     if (!self::getInstance()) {
         return NULL;
     }
     /* else */
     $bounds = ImageTTFBBox(self::$_font["size"], 0, self::$_font["family"], "W");
     $fontHeight = abs($bounds[7] - $bounds[1]);
     $bounds = ImageTTFBBox(self::$_font["size"], 0, self::$_font["family"], $txt);
     $width = abs($bounds[4] - $bounds[6]);
     $height = abs($bounds[7] - $bounds[1]);
     $offsetY = $fontHeight;
     $offsetX = 0;
     $image = imagecreate($width + self::$_padding * 2 + 1, $height + self::$_padding * 2 + 1);
     $background = ImageColorAllocate($image, self::$_backgroundColor["color"]["red"], self::$_backgroundColor["color"]["green"], self::$_backgroundColor["color"]["blue"]);
     $foreground = ImageColorAllocate($image, self::$_font["color"]["red"], self::$_font["color"]["green"], self::$_font["color"]["blue"]);
     if (self::$_transparent) {
         ImageColorTransparent($image, $background);
     }
     ImageInterlace($image, false);
     // render the image
     ImageTTFText($image, self::$_font["size"], 0, $offsetX + self::$_padding, $offsetY + self::$_padding, $foreground, self::$_font["family"], $txt);
     // print_r( self::$_font );
     return $image;
 }
开发者ID:nirwander,项目名称:holkinsengine,代码行数:25,代码来源:textImg.class.php

示例15: elseif

} elseif ($page_ip < 1000) {
    $page_ip_txt = "00000{$page_ip}";
} elseif ($page_ip < 10000) {
    $page_ip_txt = "0000{$page_ip}";
} elseif ($page_ip < 100000) {
    $page_ip_txt = "000{$page_ip}";
} elseif ($page_ip < 1000000) {
    $page_ip_txt = "00{$page_ip}";
} elseif ($page_ip < 10000000) {
    $page_ip_txt = "0{$page_ip}";
} elseif ($page_ip < 100000000) {
    $page_ip_txt = "{$page_ip}";
} else {
    $page_ip_txt = " Error!";
}
// show img -------------------------
header('Content-type: image/' . $lvc_images_format);
$imgfile = 'images/counter.' . $lvc_images_format;
$fct_imagecreatefrom = 'imagecreatefrom' . $lvc_images_format;
$img = $fct_imagecreatefrom($imgfile);
$black = imagecolorallocate($img, 0, 0, 0);
$white = imagecolorallocate($img, 255, 255, 255);
$yellow = imagecolorallocate($img, 255, 255, 0);
ImageString($img, 3, 26, 5, "{$page_ip_txt}", $black);
ImageString($img, 3, 25, 4, "{$page_ip_txt}", $white);
ImageString($img, 1, 5, 22, $count_date, $black);
ImageString($img, 1, 4, 21, $count_date, $yellow);
ImageInterlace($img, 1);
$fct_image = 'image' . $lvc_images_format;
$fct_image($img);
ImageDestroy($img);
开发者ID:nldfr219,项目名称:zhi,代码行数:31,代码来源:countimg.php


注:本文中的ImageInterlace函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。