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


PHP imageJpeg函数代码示例

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


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

示例1: save

 /**
  * 生成された画像を保存する
  *
  * @return boolean
  * @access public
  * @static
  */
 function save()
 {
     //保存先のディレクトリが存在しているかチェック
     $filePath = dirname($this->dstPath);
     if (!file_exists($filePath)) {
         mkdir($filePath);
     }
     if ($this->imageType == 'image/jpeg') {
         return imageJpeg($this->dstImage, $this->dstPath, $this->quality);
     } elseif ($this->imageType == 'image/gif') {
         return imageGif($this->dstImage, $this->dstPath);
     } elseif ($this->imageType == 'image/png') {
         return imagePng($this->dstImage, $this->dstPath);
     }
 }
开发者ID:hamhei,项目名称:onatter,代码行数:22,代码来源:thumbmake.php

示例2: resize_image

 public function resize_image($data, $imgX, $sizedef, $lid, $imgid)
 {
     $file = $data["raw_name"];
     $type = $data["file_ext"];
     $outfile = $imgX[$sizedef]['dir'] . "/" . $lid . "/" . $file . '.jpg';
     $path = $this->config->item("upload_dir");
     $image = $this->create_image_container($file, $type);
     if ($image) {
         $size = GetImageSize($path . $file . $type);
         $old = $image;
         // сей форк - не просто так. непонятно, правда, почему...
         if ($size['1'] < $size['0']) {
             $h_new = round($imgX[$sizedef]['max_dim'] * ($size['1'] / $size['0']));
             $measures = array($imgX[$sizedef]['max_dim'], $h_new);
         }
         if ($size['1'] >= $size['0']) {
             $h_new = round($imgX[$sizedef]['max_dim'] * ($size['0'] / $size['1']));
             $measures = array($h_new, $imgX[$sizedef]['max_dim']);
         }
         $new = ImageCreateTrueColor($measures[0], $measures[1]);
         ImageCopyResampled($new, $image, 0, 0, 0, 0, $measures[0], $measures[1], $size['0'], $size['1']);
         imageJpeg($new, $outfile, $imgX[$sizedef]['quality']);
         $this->db->query("UPDATE `images` SET `images`.`" . $sizedef . "` = ? WHERE `images`.`id` = ?", array(implode($measures, ","), $imgid));
         imageDestroy($new);
     }
 }
开发者ID:korzhevdp,项目名称:MiniGIS,代码行数:26,代码来源:uploadmodel.php

示例3: image_createThumb

function image_createThumb($src, $dest, $maxWidth, $maxHeight, $quality = 75)
{
    if (file_exists($src) && isset($dest)) {
        // path info
        $destInfo = pathInfo($dest);
        // image src size
        $srcSize = getImageSize($src);
        // image dest size $destSize[0] = width, $destSize[1] = height
        $srcRatio = $srcSize[0] / $srcSize[1];
        // width/height ratio
        $destRatio = $maxWidth / $maxHeight;
        if ($destRatio > $srcRatio) {
            $destSize[1] = $maxHeight;
            $destSize[0] = $maxHeight * $srcRatio;
        } else {
            $destSize[0] = $maxWidth;
            $destSize[1] = $maxWidth / $srcRatio;
        }
        // path rectification
        if ($destInfo['extension'] == "gif") {
            $dest = substr_replace($dest, 'jpg', -3);
        }
        // true color image, with anti-aliasing
        $destImage = imageCreateTrueColor($destSize[0], $destSize[1]);
        //       imageAntiAlias($destImage,true);
        // src image
        switch ($srcSize[2]) {
            case 1:
                //GIF
                $srcImage = imageCreateFromGif($src);
                break;
            case 2:
                //JPEG
                $srcImage = imageCreateFromJpeg($src);
                break;
            case 3:
                //PNG
                $srcImage = imageCreateFromPng($src);
                break;
            default:
                return false;
                break;
        }
        // resampling
        imageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destSize[0], $destSize[1], $srcSize[0], $srcSize[1]);
        // generating image
        switch ($srcSize[2]) {
            case 1:
            case 2:
                imageJpeg($destImage, $dest, $quality);
                break;
            case 3:
                imagePng($destImage, $dest);
                break;
        }
        return true;
    } else {
        return 'No such File';
    }
}
开发者ID:rolfvandervleuten,项目名称:DeepskyLog,代码行数:60,代码来源:resize.php

示例4: resizeImage

 private function resizeImage($file, $data, $tmd = 600, $quality = 100)
 {
     $data['type'] = "image/jpeg";
     $basename = basename($file);
     $filesDir = $this->input->post('uploadDir');
     // хэш нередактируемой карты!
     $uploaddir = implode(array($this->input->server('DOCUMENT_ROOT'), 'storage', $tmd, $filesDir), DIRECTORY_SEPARATOR);
     $srcFile = implode(array($this->input->server('DOCUMENT_ROOT'), 'storage', 'source', $filesDir, $basename), DIRECTORY_SEPARATOR);
     $image = $this->createimageByType($data, $srcFile);
     if (!file_exists($uploaddir)) {
         mkdir($uploaddir, 0775, true);
     }
     $size = GetImageSize($srcFile);
     $new = ImageCreateTrueColor($size['1'], $size['0']);
     if ($size['1'] > $tmd || $size['0'] > $tmd) {
         if ($size['1'] < $size['0']) {
             $hNew = round($tmd * $size['1'] / $size['0']);
             $new = ImageCreateTrueColor($tmd, $hNew);
             ImageCopyResampled($new, $image, 0, 0, 0, 0, $tmd, $hNew, $size['0'], $size['1']);
         }
         if ($size['1'] >= $size['0']) {
             $hNew = round($tmd * $size['0'] / $size['1']);
             $new = ImageCreateTrueColor($hNew, $tmd);
             ImageCopyResampled($new, $image, 0, 0, 0, 0, $hNew, $tmd, $size['0'], $size['1']);
         }
     }
     //print $uploaddir."/".TMD."/".$filename.".jpg<br>";
     imageJpeg($new, $uploaddir . DIRECTORY_SEPARATOR . $basename, $quality);
     //header("content-type: image/jpeg");// активировать для отладки
     //imageJpeg ($new, "", 100);//активировать для отладки
     imageDestroy($new);
 }
开发者ID:korzhevdp,项目名称:freehand,代码行数:32,代码来源:upload.php

示例5: generate_thumbnail

function generate_thumbnail($file, $mime)
{
    global $config;
    gd_capabilities();
    list($file_type, $exact_type) = explode("/", $mime);
    if (_JB_GD_INSTALLED && ($file_type = "image")) {
        if ($exact_type != "gif" && $exact_type != "png" && $exact_type != "jpeg") {
            return false;
        }
        if ($exact_type == "gif" && !_JB_GD_GIF) {
            return false;
        }
        if ($exact_type == "png" && !_JB_GD_PNG) {
            return false;
        }
        if ($exact_type == "jpeg" && !_JB_GD_JPG) {
            return false;
        }
        // Load up the original and get size
        //  NOTE: use imageCreateFromString to avoid to have to check what type of image it is
        $original = imageCreateFromString(file_get_contents($file));
        $original_w = imagesX($original);
        $original_h = imagesY($original);
        // Only if the image is really too big, resize it
        // NOTE: if image is smaller than target size, don't do anything.
        //  We *could* copy the original to filename_thumb, but since it's the same
        //  it would be a waste of precious resources
        if ($original_w > $config['uploader']['thumb_w'] || $original_h > $config['uploader']['thumb_h']) {
            // If original is wider than it's high, resize the width and vice versa
            // NOTE: '>=' cause otherwise it's possible that $scale isn't computed
            if ($original_w >= $original_h) {
                $scaled_w = $config['uploader']['thumb_w'];
                // Figure out how much smaller that target is than original
                //  and apply it to height
                $scale = $config['uploader']['thumb_w'] / $original_w;
                $scaled_h = ceil($original_h * $scale);
            } elseif ($original_w <= $original_h) {
                $scaled_h = $config['uploader']['thumb_h'];
                $scale = $config['uploader']['thumb_h'] / $original_h;
                $scaled_w = ceil($original_w * $scale);
            }
        } else {
            // Break out of if($file_type = image) since no resize is possible
            return false;
        }
        // Scale the image
        $scaled = imageCreateTrueColor($scaled_w, $scaled_h);
        imageCopyResampled($scaled, $original, 0, 0, 0, 0, $scaled_w, $scaled_h, $original_w, $original_h);
        // Store thumbs in jpeg, hope no one minds the 100% quality lol
        imageJpeg($scaled, $file . "_thumb", 100);
        // Let's be nice to our server
        imagedestroy($scaled);
        imagedestroy($original);
        return true;
    }
}
开发者ID:victorjacobs,项目名称:jetbird,代码行数:56,代码来源:image.functions.php

示例6: writeCopy

 function writeCopy($filename, $width, $height) {
          if($this->isLoaded()) {
              $imageNew = imageCreate($width, $height);
              if(!$imageNew) {
                  echo "ERREUR : Nouvelle image non créée";
              }
              imageCopyResized($imageNew, $this->image, 0, 0, 0, 0, $width, $height, $this->width, $this->height);
              imageJpeg($imageNew, $filename);
          }
 }
开发者ID:nidtropical,项目名称:nidtropical_old,代码行数:10,代码来源:index.php

示例7: saveFile

 public static function saveFile($image = null, $destFile = null, $saveType = self::SAVE_JPG)
 {
     switch ($saveType) {
         case self::SAVE_GIF:
             return @imageGif($image, $destFile);
         case self::SAVE_JPG:
             return @imageJpeg($image, $destFile, self::SAVE_QUALITY);
         case self::SAVE_PNG:
             return @imagePng($image, $destFile);
         default:
             return false;
     }
 }
开发者ID:yunsite,项目名称:hhzuitu,代码行数:13,代码来源:Image.class.php

示例8: createTestImage

 /**
  * Create test image.
  *
  * @param string $filename
  * @return void
  */
 protected function createTestImage($filename)
 {
     $filename = $this->getFullPath($filename);
     if (!file_exists($filename)) {
         // Create an image with the specified dimensions
         $image = imageCreate(300, 200);
         // Create a color (this first call to imageColorAllocate
         //  also automatically sets the image background color)
         $colorYellow = imageColorAllocate($image, 255, 255, 0);
         // Draw a rectangle
         imageFilledRectangle($image, 50, 50, 250, 150, $colorYellow);
         $directory = dirname($filename);
         if (!file_exists($directory)) {
             mkdir($directory, 0777, true);
         }
         imageJpeg($image, $filename);
         // Release memory
         imageDestroy($image);
     }
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:26,代码来源:MediaGallery.php

示例9: make_img

function make_img($content)
{
    $timage = array(strlen($content) * 20 + 10, 28);
    // array(largeur, hauteur) de l'image; ici la largeur est fonction du nombre de lettre du contenu, on peut bien sur mettre une largeur fixe.
    $content = preg_replace('/(\\w)/', '\\1 ', $content);
    // laisse plus d'espace entre les lettres
    $image = imagecreatetruecolor($timage[0], $timage[1]);
    // création de l'image
    // definition des couleurs
    $fond = imageColorAllocate($image, 240, 255, 240);
    $grey = imageColorAllocate($image, 210, 210, 210);
    $text_color = imageColorAllocate($image, rand(0, 100), rand(0, 50), rand(0, 60));
    imageFill($image, 0, 0, $fond);
    // on remplit l'image de blanc
    //On remplit l'image avec des polygones
    for ($i = 0, $imax = mt_rand(3, 5); $i < $imax; $i++) {
        $x = mt_rand(3, 10);
        $poly = array();
        for ($j = 0; $j < $x; $j++) {
            $poly[] = mt_rand(0, $timage[0]);
            $poly[] = mt_rand(0, $timage[1]);
        }
        imageFilledPolygon($image, $poly, $x, imageColorAllocate($image, mt_rand(150, 255), mt_rand(150, 255), mt_rand(150, 255)));
    }
    // Création des pixels gris
    for ($i = 0; $i < $timage[0] * $timage[1] / rand(15, 18); $i++) {
        imageSetPixel($image, rand(0, $timage[0]), rand(0, $timage[1]), $grey);
    }
    // affichage du texte demandé; on le centre en hauteur et largeur (à peu près ^^")
    //imageString($image, 5, ceil($timage[0]-strlen($content)*8)/2, ceil($timage[1]/2)-9, $content, $text_color);
    $longueur_chaine = strlen($content);
    for ($ch = 0; $ch < $longueur_chaine; $ch++) {
        imagettftext($image, 18, mt_rand(-30, 30), 10 * ($ch + 1), mt_rand(18, 20), $text_color, 'res/georgia.ttf', $content[$ch]);
    }
    $type = function_exists('imageJpeg') ? 'jpeg' : 'png';
    @header('Content-Type: image/' . $type);
    @header('Cache-control: no-cache, no-store');
    $type == 'png' ? imagePng($image) : imageJpeg($image);
    ImageDestroy($image);
    exit;
}
开发者ID:shiooooooookun,项目名称:Nouweo_PHP,代码行数:41,代码来源:captcha.php

示例10: resizeImage

function resizeImage($file, $max_x, $max_y, $forcePng = false)
{
    if ($max_x <= 0 || $max_y <= 0) {
        $max_x = 5;
        $max_y = 5;
    }
    $src = BASEDIR . '/avatars/' . $file;
    list($width, $height, $type) = getImageSize($src);
    $scale = min($max_x / $width, $max_y / $height);
    $newWidth = $width * $scale;
    $newHeight = $height * $scale;
    $img = imagecreatefromstring(file_get_contents($src));
    $black = imagecolorallocate($img, 0, 0, 0);
    $resizedImage = imageCreateTrueColor($newWidth, $newHeight);
    imagecolortransparent($resizedImage, $black);
    imageCopyResampled($resizedImage, $img, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
    imageDestroy($img);
    unlink($src);
    if (!$forcePng) {
        switch ($type) {
            case IMAGETYPE_JPEG:
                imageJpeg($resizedImage, BASEDIR . '/avatars/' . $file);
                break;
            case IMAGETYPE_GIF:
                imageGif($resizedImage, BASEDIR . '/avatars/' . $file);
                break;
            case IMAGETYPE_PNG:
                imagePng($resizedImage, BASEDIR . '/avatars/' . $file);
                break;
            default:
                imagePng($resizedImage, BASEDIR . '/avatars/' . $file);
                break;
        }
    } else {
        imagePng($resizedImage, BASEDIR . '/avatars/' . $file . '.png');
    }
    return;
}
开发者ID:kandran,项目名称:flyspray,代码行数:38,代码来源:modify.inc.php

示例11: save

 function save($filename, $type = 'png', $quality = 100)
 {
     $this->_build();
     $this->_build_border();
     switch ($type) {
         case 'gif':
             $ret = imageGif($this->_dest_image, $filename);
             break;
         case 'jpg':
         case 'jpeg':
             $ret = imageJpeg($this->_dest_image, $filename, $quality);
             break;
         case 'png':
             $ret = imagePng($this->_dest_image, $filename);
             break;
         default:
             $this->_error('Save: Invalid Format');
             break;
     }
     if (!$ret) {
         $this->_error('Save: Unable to save');
     }
 }
开发者ID:mbassan,项目名称:backstage2,代码行数:23,代码来源:Image.php

示例12: resizeJpeg

 private function resizeJpeg($newW, $newH, $oWidth, $oHeight, $fullPath)
 {
     // create a new canvas
     $im = ImageCreateTruecolor($newW, $newH);
     $baseImage = ImageCreateFromJpeg($this->imageName);
     // if successful this returns as true - this is the actual resizing
     if (imagecopyresampled($im, $baseImage, 0, 0, 0, 0, $newW, $newH, $oWidth, $oHeight)) {
         // resizing is successful and saved to $fullPath
         imageJpeg($im, $fullPath);
         if (file_exists($fullPath)) {
             $this->msg .= 'Resized file created<br />';
             imagedestroy($im);
             // don't really need this cos $im will disappear after function done
             return true;
         } else {
             $this->msg .= 'Failure in resize jpeg<br />';
         }
     } else {
         // resizing fails
         $this->msg .= 'Unable to resize image<br />';
         return false;
     }
 }
开发者ID:Juterpillar,项目名称:artprints,代码行数:23,代码来源:resizeImageClass.php

示例13: createThumbMobile

 function createThumbMobile($src, $dest, $desired_width)
 {
     $max_h = 68;
     $max_w = 80;
     if ($max_w > $max_h) {
         $max_h = $max_w;
     } else {
         if ($max_h > $max_w) {
             $max_w = $max_h;
         }
     }
     $size = getImageSize($src);
     $old_w = $size[0];
     $old_h = $size[1];
     if ($old_w > $old_h) {
         $nw = $max_w;
         $nh = $old_h * ($max_w / $old_w);
     }
     if ($old_w < $old_h) {
         $nw = $old_w * ($max_h / $old_h);
         $nh = $max_h;
     }
     if ($old_w == $old_h) {
         $nw = $max_w;
         $nh = $max_h;
     }
     // Building the intermediate resized thumbnail
     $resimage = imagecreatefromjpeg($src);
     $newimage = imagecreatetruecolor($nw, $nh);
     // use alternate function if not installed
     imageCopyResampled($newimage, $resimage, 0, 0, 0, 0, $nw, $nh, $old_w, $old_h);
     // Making the final cropped thumbnail
     $viewimage = imagecreatetruecolor($max_w, $max_h);
     $bg = imagecolorallocate($viewimage, 255, 255, 255);
     imagefill($viewimage, 0, 0, $bg);
     imagecopy($viewimage, $newimage, 0, 0, 0, 0, $nw, $nh);
     // saving
     imageJpeg($viewimage, $dest, 85);
 }
开发者ID:keyanmca,项目名称:yoga,代码行数:39,代码来源:AdminController.php

示例14: Main


//.........这里部分代码省略.........
                             // サイズが同じ場合には、そのままコピーする。(画質劣化を防ぐ)
                             copy($path, $dst_file);
                         } else {
                             imagepng($dst_im, $dst_file);
                         }
                     }
                     imagedestroy($src_im);
                     imagedestroy($dst_im);
                 }
             } else {
                 // サムネイル作成不可の場合(旧バージョン対策)
                 $dst_im = imageCreate($re_size[0], $re_size[1]);
                 imageColorAllocate($dst_im, 255, 255, 214);
                 //背景色
                 // 枠線と文字色の設定
                 $black = imageColorAllocate($dst_im, 0, 0, 0);
                 $red = imageColorAllocate($dst_im, 255, 0, 0);
                 imagestring($dst_im, 5, 10, 10, "GIF {$size['0']}x{$size['1']}", $red);
                 imageRectangle($dst_im, 0, 0, $re_size[0] - 1, $re_size[1] - 1, $black);
                 // 画像出力
                 if ($header) {
                     header("Content-Type: image/png");
                     imagepng($dst_im);
                     return "";
                 } else {
                     $dst_file = $dst_file . ".png";
                     imagepng($dst_im, $dst_file);
                 }
                 imagedestroy($src_im);
                 imagedestroy($dst_im);
             }
             break;
             // jpg形式
         // jpg形式
         case "2":
             $src_im = imageCreateFromJpeg($path);
             $dst_im = $imagecreate($re_size[0], $re_size[1]);
             $imageresize($dst_im, $src_im, 0, 0, 0, 0, $re_size[0], $re_size[1], $size[0], $size[1]);
             // 画像出力
             if ($header) {
                 header("Content-Type: image/jpeg");
                 imageJpeg($dst_im);
                 return "";
             } else {
                 $dst_file = $dst_file . ".jpg";
                 if ($re_size[0] == $size[0] && $re_size[1] == $size[1]) {
                     // サイズが同じ場合には、そのままコピーする。(画質劣化を防ぐ)
                     copy($path, $dst_file);
                 } else {
                     imageJpeg($dst_im, $dst_file);
                 }
             }
             imagedestroy($src_im);
             imagedestroy($dst_im);
             break;
             // png形式
         // png形式
         case "3":
             $src_im = imageCreateFromPNG($path);
             $colortransparent = imagecolortransparent($src_im);
             $has_alpha = ord(file_get_contents($path, false, null, 25, 1)) & 0x4;
             if ($colortransparent > -1 || $has_alpha) {
                 $dst_im = $imagecreate($re_size[0], $re_size[1]);
                 // アルファチャンネルが存在する場合はそちらを使用する
                 if ($has_alpha) {
                     imagealphablending($dst_im, false);
                     imagesavealpha($dst_im, true);
                 }
                 imagepalettecopy($dst_im, $src_im);
                 imagefill($dst_im, 0, 0, $colortransparent);
                 imagecolortransparent($dst_im, $colortransparent);
                 imagecopyresized($dst_im, $src_im, 0, 0, 0, 0, $re_size[0], $re_size[1], $size[0], $size[1]);
             } else {
                 $dst_im = $imagecreate($re_size[0], $re_size[1]);
                 imagecopyresized($dst_im, $src_im, 0, 0, 0, 0, $re_size[0], $re_size[1], $size[0], $size[1]);
                 imagecolorstotal($src_im) == 0 ? $colortotal = 65536 : ($colortotal = imagecolorstotal($src_im));
                 imagetruecolortopalette($dst_im, true, $colortotal);
             }
             // 画像出力
             if ($header) {
                 header("Content-Type: image/png");
                 imagepng($dst_im);
                 return "";
             } else {
                 $dst_file = $dst_file . ".png";
                 if ($re_size[0] == $size[0] && $re_size[1] == $size[1]) {
                     // サイズが同じ場合には、そのままコピーする。(画質劣化を防ぐ)
                     copy($path, $dst_file);
                 } else {
                     imagepng($dst_im, $dst_file);
                 }
             }
             imagedestroy($src_im);
             imagedestroy($dst_im);
             break;
         default:
             return array(0, "イメージの形式が不明です。");
     }
     return array(1, $dst_file);
 }
开发者ID:casan,项目名称:eccube-2_13,代码行数:101,代码来源:gdthumb.php

示例15: ImageWrite

 /**
  * Writes the input GDlib image pointer to file
  *
  * @param resource $destImg The GDlib image resource pointer
  * @param string $theImage The filename to write to
  * @param int $quality The image quality (for JPEGs)
  * @return bool The output of either imageGif, imagePng or imageJpeg based on the filename to write
  * @see maskImageOntoImage(), scale(), output()
  */
 public function ImageWrite($destImg, $theImage, $quality = 0)
 {
     imageinterlace($destImg, 0);
     $ext = strtolower(substr($theImage, strrpos($theImage, '.') + 1));
     $result = false;
     switch ($ext) {
         case 'jpg':
         case 'jpeg':
             if (function_exists('imageJpeg')) {
                 if ($quality == 0) {
                     $quality = $this->jpegQuality;
                 }
                 $result = imageJpeg($destImg, $theImage, $quality);
             }
             break;
         case 'gif':
             if (function_exists('imageGif')) {
                 imagetruecolortopalette($destImg, true, 256);
                 $result = imageGif($destImg, $theImage);
             }
             break;
         case 'png':
             if (function_exists('imagePng')) {
                 $result = ImagePng($destImg, $theImage);
             }
             break;
     }
     if ($result) {
         GeneralUtility::fixPermissions($theImage);
     }
     return $result;
 }
开发者ID:TYPO3Incubator,项目名称:TYPO3.CMS,代码行数:41,代码来源:GraphicalFunctions.php


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