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


PHP imagecreatefromjpeg函数代码示例

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


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

示例1: load

 static function load($filename)
 {
     $info = getimagesize($filename);
     list($width, $height) = $info;
     if (!$width || !$height) {
         return null;
     }
     $image = null;
     switch ($info['mime']) {
         case 'image/gif':
             $image = imagecreatefromgif($filename);
             break;
         case 'image/jpeg':
             $image = imagecreatefromjpeg($filename);
             break;
         case 'image/png':
             $image = imagecreatetruecolor($width, $height);
             $white = imagecolorallocate($image, 255, 255, 255);
             imagefill($image, 0, 0, $white);
             $png = imagecreatefrompng($filename);
             imagealphablending($png, true);
             imagesavealpha($png, true);
             imagecopy($image, $png, 0, 0, 0, 0, $width, $height);
             imagedestroy($png);
             break;
     }
     if ($image) {
         return new image($image, $width, $height);
     } else {
         return null;
     }
 }
开发者ID:nyan-cat,项目名称:easyweb,代码行数:32,代码来源:image.php

示例2: hacknrollify

function hacknrollify($picfilename)
{
    $logofilename = "logo.png";
    $logoPicPath = "logopics/" . $logofilename;
    $originalPicPath = "originalpics/" . $picfilename;
    $editedfilename = "hnr_" . $picfilename;
    $editedPicPath = "editedpics/" . $editedfilename;
    // read the original image from file
    $profilepic = imagecreatefromjpeg($originalPicPath);
    $profilepicWidth = imagesx($profilepic);
    $profilepicHeight = imagesy($profilepic);
    // create the black image overlay
    $blackoverlay = imagecreate($profilepicWidth, $profilepicHeight);
    imagecolorallocate($blackoverlay, 0, 0, 0);
    // then merge the black and profilepic
    imagecopymerge($profilepic, $blackoverlay, 0, 0, 0, 0, $profilepicWidth, $profilepicHeight, 50);
    imagedestroy($blackoverlay);
    // merge the resized logo
    $logo = resizeImage($logoPicPath, $profilepicWidth - 80, 999999);
    imageAlphaBlending($logo, false);
    imageSaveAlpha($logo, true);
    $logoWidth = imagesx($logo);
    $logoHeight = imagesy($logo);
    $verticalOffset = $profilepicHeight / 2 - $logoHeight / 2;
    $horizontalOffset = 40;
    imagecopyresampled($profilepic, $logo, $horizontalOffset, $verticalOffset, 0, 0, $logoWidth, $logoHeight, $logoWidth, $logoHeight);
    $mergeSuccess = imagejpeg($profilepic, $editedPicPath);
    if (!$mergeSuccess) {
        echo "Image merge failed!";
    }
    imagedestroy($profilepic);
    imagedestroy($logo);
    return $editedPicPath;
}
开发者ID:nicholaslum444,项目名称:HacknRollify,代码行数:34,代码来源:lib_hacknrollify.php

示例3: createthumb

function createthumb($originalImage, $new_w, $new_h)
{
    $src_img = imagecreatefromjpeg("uploads/" . $originalImage);
    # Add the _t to our image name
    list($imageName, $extension) = explode(".", $originalImage);
    $newName = $imageName . "_t." . $extension;
    # Maintain proportions
    $old_x = imageSX($src_img);
    $old_y = imageSY($src_img);
    if ($old_x > $old_y) {
        $thumb_w = $new_w;
        $thumb_h = $old_y * ($new_h / $old_x);
    }
    if ($old_x < $old_y) {
        $thumb_w = $old_x * ($new_w / $old_y);
        $thumb_h = $new_h;
    }
    if ($old_x == $old_y) {
        $thumb_w = $new_w;
        $thumb_h = $new_h;
    }
    # Create destination-image-resource
    $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
    # Copy source-image-resource to destination-image-resource
    imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
    # Create the final image from the destination-image-resource
    imagejpeg($dst_img, "uploads/" . $newName);
    # Delete our image-resources
    imagedestroy($dst_img);
    imagedestroy($src_img);
    # Show results
    return $newName;
}
开发者ID:ritarafaeli,项目名称:notes,代码行数:33,代码来源:uploaderExample_functions.php

示例4: load

 /**
  * Load an image
  *
  * @param $filename
  * @return Image
  * @throws Exception
  */
 public static function load($filename)
 {
     $instance = new self();
     // Require GD library
     if (!extension_loaded('gd')) {
         throw new Exception('Required extension GD is not loaded.');
     }
     $instance->filename = $filename;
     $info = getimagesize($instance->filename);
     switch ($info['mime']) {
         case 'image/gif':
             $instance->image = imagecreatefromgif($instance->filename);
             break;
         case 'image/jpeg':
             $instance->image = imagecreatefromjpeg($instance->filename);
             break;
         case 'image/png':
             $instance->image = imagecreatefrompng($instance->filename);
             imagesavealpha($instance->image, true);
             imagealphablending($instance->image, true);
             break;
         default:
             throw new Exception('Invalid image: ' . $instance->filename);
             break;
     }
     $instance->original_info = array('width' => $info[0], 'height' => $info[1], 'orientation' => $instance->get_orientation(), 'exif' => function_exists('exif_read_data') ? $instance->exif = @exif_read_data($instance->filename) : null, 'format' => preg_replace('/^image\\//', '', $info['mime']), 'mime' => $info['mime']);
     $instance->width = $info[0];
     $instance->height = $info[1];
     imagesavealpha($instance->image, true);
     imagealphablending($instance->image, true);
     return $instance;
 }
开发者ID:SerdarSanri,项目名称:arx-core,代码行数:39,代码来源:Image.php

示例5: upload

function upload($tmp, $name, $nome, $larguraP, $pasta)
{
    $ext = strtolower(end(explode('.', $name)));
    if ($ext == 'jpg') {
        $img = imagecreatefromjpeg($tmp);
    } elseif ($ext == 'gif') {
        $img = imagecreatefromgif($tmp);
    } else {
        $img = imagecreatefrompng($tmp);
    }
    $x = imagesx($img);
    $y = imagesy($img);
    $largura = $x > $larguraP ? $larguraP : $x;
    $altura = $largura * $y / $x;
    if ($altura > $larguraP) {
        $altura = $larguraP;
        $largura = $altura * $x / $y;
    }
    $nova = imagecreatetruecolor($largura, $altura);
    imagecopyresampled($nova, $img, 0, 0, 0, 0, $largura, $altura, $x, $y);
    imagejpeg($nova, "{$pasta}/{$nome}");
    imagedestroy($img);
    imagedestroy($nova);
    return $nome;
}
开发者ID:mauriliovilela,项目名称:ser-social,代码行数:25,代码来源:funcoes.php

示例6: resize

function resize($photo_src, $width, $name)
{
    $parametr = getimagesize($photo_src);
    list($width_orig, $height_orig) = getimagesize($photo_src);
    $ratio_orig = $width_orig / $height_orig;
    $new_width = $width;
    $new_height = $width / $ratio_orig;
    $newpic = imagecreatetruecolor($new_width, $new_height);
    $col2 = imagecolorallocate($newpic, 255, 255, 255);
    imagefilledrectangle($newpic, 0, 0, $new_width, $new_width, $col2);
    switch ($parametr[2]) {
        case 1:
            $image = imagecreatefromgif($photo_src);
            break;
        case 2:
            $image = imagecreatefromjpeg($photo_src);
            break;
        case 3:
            $image = imagecreatefrompng($photo_src);
            break;
    }
    imagecopyresampled($newpic, $image, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
    imagejpeg($newpic, $name, 100);
    return true;
}
开发者ID:pioytazsko,项目名称:garantmarket,代码行数:25,代码来源:new_item.php

示例7: GetPartialImage

function GetPartialImage($url)
{
	$W = 150;
	$H = 130;
	$F = 80;
	$STEP = 1.0 / $F;
	$im = imagecreatefromjpeg($url);
	$dest = imagecreatetruecolor($W, $H);
	imagecopy($dest, $im, 0, 0, 35, 40, $W, $H);
	
	$a = 1;
	for( $y = $H - $F; $y < $H; $y++ )
	{
		for ( $x = 0; $x < $W; $x++ )
		{
			$i = imagecolorat($dest, $x, $y);
			$c = imagecolorsforindex($dest, $i);
			$c = imagecolorallocate($dest, 
				a($c['red'], $a),
				a($c['green'], $a), 
				a($c['blue'], $a)
			);
			imagesetpixel($dest, $x, $y, $c);
		}
		$a -= $STEP;
	}
	
	header('Content-type: image/png');
	imagepng($dest);
	imagedestroy($dest);
	imagedestroy($im);
}
开发者ID:ryanknu,项目名称:Cuber,代码行数:32,代码来源:image.php

示例8: mkdir

             mkdir($dir . $p, 0755);
         }
     }
     return $p;
 }
 private static function _init($file)
 {
     $info = getimagesize($file);
     $method = $im = $ext = null;
     switch ($info['mime']) {
         case 'image/jpeg':
         case 'image/jpg':
             $ext = '.jpg';
             $im = imagecreatefromjpeg($file);
             $method = 'imagejpeg';
             break;
         case 'image/gif':
             $ext = '.gif';
             $im = imagecreatefromgif($file);
             $method = 'imagegif';
             break;
         case 'image/png':
             $ext = '.png';
             $im = imagecreatefrompng($file);
             $method = 'imagepng';
             break;
         case 'image/bmp':
             $ext = '.bmp';
             $im = imagecreatefrombmp($file);
             $method = 'imagepng';
             break;
开发者ID:xiaoniainiu,项目名称:php-yaf-yk,代码行数:31,代码来源:upload.php

示例9: background

 function background()
 {
     $im = imagecreatetruecolor($this->width, $this->height);
     $bgs = array();
     if ($this->style & 8 && function_exists('imagecreatefromjpeg') && function_exists('imagecopymerge')) {
         if ($fp = @opendir($GLOBALS['imgdir'] . '/ck/bg/')) {
             while ($flie = @readdir($fp)) {
                 if (preg_match('/\\.jpg$/i', $flie)) {
                     $bgs[] = $GLOBALS['imgdir'] . '/ck/bg/' . $flie;
                 }
             }
             @closedir($fp);
         }
     }
     if ($bgs) {
         $imbg = imagecreatefromjpeg($bgs[array_rand($bgs)]);
         imagecopymerge($im, $imbg, 0, 0, mt_rand(0, 200 - $this->width), mt_rand(0, 80 - $this->height), $this->width, $this->height, 100);
         imagedestroy($imbg);
     } else {
         $c = array();
         for ($i = 0; $i < 3; $i++) {
             $c[$i] = mt_rand(200, 255);
             $step[$i] = (mt_rand(100, 150) - $c[$i]) / $this->width;
         }
         for ($i = 0; $i < $this->width; $i++) {
             imageline($im, $i, 0, $i, $this->height, imagecolorallocate($im, $c[0], $c[1], $c[2]));
             $c[0] += $step[0];
             $c[1] += $step[1];
             $c[2] += $step[2];
         }
     }
     return $im;
 }
开发者ID:adi00,项目名称:wumaproject,代码行数:33,代码来源:ck.php

示例10: openImage

 private function openImage($file)
 {
     // *** Get extension
     $extension = strtolower(strrchr($file, '.'));
     //$extension = DataHandler::returnExtensionOfFile($file);
     switch ($extension) {
         case '.jpg':
         case '.jpeg':
             $img = @imagecreatefromjpeg($file);
             break;
         case '.gif':
             $img = @imagecreatefromgif($file);
             break;
         case '.png':
             $img = @ImageCreateFromPNG($file);
             //                        //abaixo do php.net
             //                        imagealphablending($img, false);
             //						imagesavealpha($img, true);
             break;
         default:
             $img = false;
             break;
     }
     return $img;
 }
开发者ID:reytuty,项目名称:facil,代码行数:25,代码来源:ResizeImage.class.php

示例11: __construct

 public function __construct($filepath)
 {
     if (!function_exists('gd_info')) {
         throw new Hayate_Exception(_('GD extension is missing.'));
     }
     if (!is_file($filepath)) {
         throw new Hayate_Exception(sprintf(_('Cannot find %s'), $filepath));
     }
     $this->filepath = $filepath;
     $info = getimagesize($this->filepath);
     if (false === $info) {
         throw new Hayate_Exception(sprintf(_('Cannot read %s'), $filepath));
     }
     list($this->width, $this->height) = $info;
     $mimes = array('image/jpeg' => 'jpg', 'image/pjpeg' => 'jpg', 'image/gif' => 'gif', 'image/png' => 'png');
     $this->ext = isset($mimes[$info['mime']]) ? $mimes[$info['mime']] : null;
     if (null === $this->ext) {
         throw new Hayate_Exception(sprintf(_('Supported mime types are: %s'), implode(',', array_keys($mimes))));
     }
     switch ($this->ext) {
         case 'jpg':
             $this->img = imagecreatefromjpeg($filepath);
             break;
         case 'gif':
             $this->img = imagecreatefromgif($filepath);
             break;
         case 'png':
             $this->img = imagecreatefrompng($filepath);
             break;
     }
 }
开发者ID:hayate,项目名称:hayate,代码行数:31,代码来源:Image.php

示例12: cropnsave

 public function cropnsave($id)
 {
     $basepath = app_path() . '/storage/uploads/';
     $jpeg_quality = 90;
     $src = $basepath . 'resize_' . $id;
     if (ImageModel::getImgTypeByExtension($id) == ImageModel::IMGTYPE_PNG) {
         $img_r = imagecreatefrompng($src);
     } else {
         $img_r = imagecreatefromjpeg($src);
     }
     $dst_r = ImageCreateTrueColor(Input::get('w'), Input::get('h'));
     imagecopyresampled($dst_r, $img_r, 0, 0, Input::get('x'), Input::get('y'), Input::get('w'), Input::get('h'), Input::get('w'), Input::get('h'));
     $filename = $basepath . 'crop_' . $id;
     imagejpeg($dst_r, $filename, $jpeg_quality);
     $image = ImageModel::createImageModel('crop_' . $id);
     try {
         $session = Session::get('user');
         $userService = new SoapClient(Config::get('wsdl.user'));
         $currentUser = $userService->getUserById(array("userId" => $session['data']->id));
         $currentUser = $currentUser->user;
         $currentUser->avatar = $image;
         $result = $userService->updateUser(array("user" => $currentUser));
         // Cleanup
         File::delete($src);
         File::delete($filename);
         File::delete($basepath . $id);
         return Response::json($result->complete);
     } catch (Exception $ex) {
         error_log($ex);
     }
 }
开发者ID:Yatko,项目名称:Gifteng,代码行数:31,代码来源:ImageController.php

示例13: create_pic

function create_pic($upfile, $new_path, $width)
{
    $quality = 100;
    $image_path = $upfile;
    $image_info = getimagesize($image_path);
    $exname = '';
    //1  =  GIF,  2  =  JPG,  3  =  PNG,  4  =  SWF,  5  =  PSD,  6  =  BMP,  7  =  TIFF(intel  byte  order),  8  =  TIFF(motorola  byte  order),  9  =  JPC,  10  =  JP2,  11  =  JPX,  12  =  JB2,  13  =  SWC,  14  =  IFF
    switch ($image_info[2]) {
        case 1:
            @($image = imagecreatefromgif($image_path));
            $exname = 'gif';
            break;
        case 2:
            @($image = imagecreatefromjpeg($image_path));
            $exname = 'jpg';
            break;
        case 3:
            @($image = imagecreatefrompng($image_path));
            $exname = 'png';
            break;
        case 6:
            @($image = imagecreatefromwbmp($image_path));
            $exname = 'wbmp';
            break;
    }
    $T_width = $image_info[0];
    $T_height = $image_info[1];
    if (!empty($image)) {
        $image_x = imagesx($image);
        $image_y = imagesy($image);
    } else {
        return FALSE;
    }
    @chmod($new_path, 0777);
    if ($image_x > $width) {
        $x = $width;
        $y = intval($x * $image_y / $image_x);
    } else {
        @copy($image_path, $new_path . '.' . $exname);
        return $exname;
    }
    $newimage = imagecreatetruecolor($x, $y);
    imagecopyresampled($newimage, $image, 0, 0, 0, 0, $x, $y, $image_x, $image_y);
    switch ($image_info[2]) {
        case 1:
            imagegif($newimage, $new_path . '.gif', $quality);
            break;
        case 2:
            imagejpeg($newimage, $new_path . '.jpg', $quality);
            break;
        case 3:
            imagepng($newimage, $new_path . '.png', $quality);
            break;
        case 6:
            imagewbmp($newimage, $new_path . '.wbmp', $quality);
            break;
    }
    imagedestroy($newimage);
    return $exname;
}
开发者ID:yunsite,项目名称:cyaskuc,代码行数:60,代码来源:global.func.php

示例14: resizewidth

 static function resizewidth($width, $imageold, $imagenew)
 {
     $image_info = getimagesize($imageold);
     $image_type = $image_info[2];
     if ($image_type == IMAGETYPE_JPEG) {
         $image = imagecreatefromjpeg($imageold);
     } elseif ($this->image_type == IMAGETYPE_GIF) {
         $image = imagecreatefromgif($imageold);
     } elseif ($this->image_type == IMAGETYPE_PNG) {
         $image = imagecreatefrompng($imageold);
     }
     $ratio = imagesy($image) / imagesx($image);
     $height = $width * $ratio;
     //$width = imagesx($image) * $width/100;
     // $height = imagesx($image) * $width/100;
     $new_image = imagecreatetruecolor($width, $height);
     imagecopyresampled($new_image, $image, 0, 0, 0, 0, $width, $height, $image_info[0], $image_info[1]);
     $image = $new_image;
     $compression = 75;
     $permissions = null;
     if ($image_type == IMAGETYPE_JPEG) {
         imagejpeg($image, $imagenew, $compression);
     } elseif ($image_type == IMAGETYPE_GIF) {
         imagegif($image, $imagenew);
     } elseif ($image_type == IMAGETYPE_PNG) {
         imagepng($image, $imagenew);
     }
     if ($permissions != null) {
         chmod($imagenew, $permissions);
     }
 }
开发者ID:blackorwhite1233,项目名称:fakekinhdoanh,代码行数:31,代码来源:SimpleImage.php

示例15: get_image

function get_image($file)
{
    /*
    	Create a resource from image file and return it with getimagesize() array
    	$file - image file or resource
    	return array('res'=>$image_resource, 'imgsize'=>getimagesize($file))
    */
    if (is_file($file) === true && file_exists($file) === true && is_readable($file) === true) {
        $img_size = getimagesize($file);
        if ($img_size !== false) {
            $im_mime = $img_size['mime'];
            // Get the image from file
            if ($im_mime === 'image/jpeg') {
                $res = imagecreatefromjpeg($file);
            } else {
                if ($im_mime === 'image/gif') {
                    $res = imagecreatefromgif($file);
                } else {
                    if ($im_mime === 'image/png') {
                        $res = imagecreatefrompng($file);
                    } else {
                        // Exit if not supported format
                        return false;
                    }
                }
            }
            return array('res' => $res, 'imgsize' => $img_size);
        }
    }
    return false;
}
开发者ID:rosko,项目名称:Tempo-CMS,代码行数:31,代码来源:img_function.php


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