本文整理汇总了PHP中imageCreateFromJpeg函数的典型用法代码示例。如果您正苦于以下问题:PHP imageCreateFromJpeg函数的具体用法?PHP imageCreateFromJpeg怎么用?PHP imageCreateFromJpeg使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imageCreateFromJpeg函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: imageResize
function imageResize($file, $info, $destination)
{
$height = $info[1];
//высота
$width = $info[0];
//ширина
//определяем размеры будущего превью
$y = 150;
if ($width > $height) {
$x = $y * ($width / $height);
} else {
$x = $y / ($height / $width);
}
$to = imageCreateTrueColor($x, $y);
switch ($info['mime']) {
case 'image/jpeg':
$from = imageCreateFromJpeg($file);
break;
case 'image/png':
$from = imageCreateFromPng($file);
break;
case 'image/gif':
$from = imageCreateFromGif($file);
break;
default:
echo "No prevue";
break;
}
imageCopyResampled($to, $from, 0, 0, 0, 0, imageSX($to), imageSY($to), imageSX($from), imageSY($from));
imagepng($to, $destination);
imagedestroy($from);
imagedestroy($to);
}
示例2: 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';
}
}
示例3: get_any_type
protected function get_any_type($srcpath)
{
try {
$this->check_file($srcpath);
$srcSize = getImageSize($srcpath);
switch ($srcSize[2]) {
case 1:
$img = imageCreateFromGif($srcpath);
break;
case 2:
$img = imageCreateFromJpeg($srcpath);
break;
case 3:
$img = imageCreateFromPng($srcpath);
break;
default:
throw new Imgdexception('not possible to get any type - srcpath:' . $srcpath);
break;
}
$image['width'] = $srcSize[0];
$image['height'] = $srcSize[1];
$image['img'] = $img;
return $image;
} catch (Imgdexception $e) {
$e->print_debug(__FILE__, __LINE__);
return false;
}
}
示例4: load
function load()
{
if ($this->loaded) {
return true;
}
//$size = $this->get_size();
//if (!$size) throw new exception("Failed loading image");
list($this->w, $this->h, $this->type) = getImageSize($this->src);
switch ($this->type) {
case 1:
$this->img = imageCreateFromGif($this->src);
break;
case 2:
$this->img = imageCreateFromJpeg($this->src);
break;
case 3:
$this->img = imageCreateFromPng($this->src);
break;
default:
throw new exception("Unsuported image type");
break;
}
$this->loaded = true;
return true;
}
示例5: anyImgFile2Im
/**
* Using GD lib for get and transform images.
* @see http://php.net/manual/en/function.imagecreatefromjpeg.php#110547
*/
function anyImgFile2Im($fname = NULL)
{
if ($fname) {
$this->setFile($fname);
}
$allowedTypes = [1, 2, 3, 6];
// gif,jpg,png,bmp
if (!in_array($this->ftype, $allowedTypes)) {
return false;
}
switch ($this->ftype) {
case 1:
$im = imageCreateFromGif($this->fname);
break;
case 2:
$im = imageCreateFromJpeg($this->fname);
break;
case 3:
$im = imageCreateFromPng($this->fname);
// echo "\n degug {$this->fname}";
break;
case 6:
$im = imageCreateFromBmp($this->fname);
break;
}
return $im;
}
示例6: load
/**
* Load image from $fileName
*
* @throws Zend_Image_Driver_Exception
* @param string $fileName Path to image
*/
public function load($fileName)
{
parent::load($fileName);
$this->_imageLoaded = false;
$info = getimagesize($fileName);
switch ($this->_type) {
case 'jpg':
$this->_image = imageCreateFromJpeg($fileName);
if ($this->_image !== false) {
$this->_imageLoaded = true;
}
break;
case 'png':
$this->_image = imageCreateFromPng($fileName);
if ($this->_image !== false) {
$this->_imageLoaded = true;
}
break;
case 'gif':
$this->_image = imageCreateFromGif($fileName);
if ($this->_image !== false) {
$this->_imageLoaded = true;
}
break;
}
}
示例7: make_thumb
/**
* Generate a thumbnail from an image
*
*/
function make_thumb($source, $destination, $size)
{
// Check if GD is installed
if (extension_loaded('gd') && function_exists('imageCreateFromJpeg')) {
// First figure out the size of the thumbnail
list($original_x, $original_y) = getimagesize($source);
if ($original_x > $original_y) {
$thumb_w = $size;
$thumb_h = $original_y * ($size / $original_x);
}
if ($original_x < $original_y) {
$thumb_w = $original_x * ($size / $original_y);
$thumb_h = $size;
}
if ($original_x == $original_y) {
$thumb_w = $size;
$thumb_h = $size;
}
// Now make the thumbnail
$source = imageCreateFromJpeg($source);
$dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
imagecopyresampled($dst_img, $source, 0, 0, 0, 0, $thumb_w, $thumb_h, $original_x, $original_y);
imagejpeg($dst_img, $destination);
// Clear memory
imagedestroy($dst_img);
imagedestroy($source);
// Return true
return true;
} else {
return false;
}
}
示例8: imageCreateFromAny
function imageCreateFromAny($filepath)
{
list($w, $h, $t, $attr) = getimagesize($filepath);
// [] if you don't have exif you could use getImageSize()
$allowedTypes = array(IMG_GIF, IMG_JPG, IMG_PNG, IMG_WBMP);
if (!in_array($t, $allowedTypes)) {
return false;
}
switch ($t) {
case IMG_GIF:
$im = imageCreateFromGif($filepath);
echo 'type image GIF';
break;
case IMG_JPG:
$im = imageCreateFromJpeg($filepath);
echo 'type image JPG';
break;
case IMG_PNG:
$im = imageCreateFromPng($filepath);
echo 'type image PNG';
break;
case IMG_WBMP:
$im = imageCreateFromwBmp($filepath);
echo 'type image BMP';
break;
}
echo 'source : ' . $filepath . ' | im : ' . $im;
return $im;
}
示例9: imagecreator
function imagecreator($filename)
{
$nx = 16;
$ny = 8;
$zoom = 4;
$im = imageCreateFromJpeg("uploads/" . $filename);
$temp_dir = "dir_{$filename}";
mkdir("uploads/" . $temp_dir, 0744);
$temp_dir = "uploads/" . $temp_dir;
//return;
$imSX = imageSX($im);
$imSY = imageSY($im);
$kusokX = $imSX / $nx;
$kusokY = $imSY / $ny;
for ($k = 0; $k < $ny; $k++) {
for ($i = 0; $i < $nx; $i++) {
$im2 = imagecreatetruecolor(512, 512);
imagecopyresized($im2, $im, 0, 0, $i * $kusokX, $k * $kusokY, 512, 512, $kusokX, $kusokY);
//imageInterlace($im2, 1);
imagejpeg($im2, "{$temp_dir}/" . "1_{$zoom}_{$i}_{$k}_.jpeg", 90);
$im2 = null;
}
}
$factor = 2;
$zoom = $zoom - 1;
for ($k = 0; $k < $ny / $factor; $k++) {
for ($i = 0; $i < $nx / $factor; $i++) {
$im2 = imagecreatetruecolor(512, 512);
imagecopyresized($im2, $im, 0, 0, $i * $kusokX * $factor, $k * $kusokY * $factor, 512, 512, $kusokX * $factor, $kusokY * $factor);
//imageInterlace($im2, 1);
imagejpeg($im2, "{$temp_dir}/" . "1_{$zoom}_{$i}_{$k}_.jpeg", 90);
$im2 = null;
}
}
$factor = 4;
$zoom = $zoom - 1;
for ($k = 0; $k < $ny / $factor; $k++) {
for ($i = 0; $i < $nx / $factor; $i++) {
$im2 = imagecreatetruecolor(512, 512);
imagecopyresized($im2, $im, 0, 0, $i * $kusokX * $factor, $k * $kusokY * $factor, 512, 512, $kusokX * $factor, $kusokY * $factor);
//imageInterlace($im2, 1);
imagejpeg($im2, "{$temp_dir}/" . "1_{$zoom}_{$i}_{$k}_.jpeg", 90);
$im2 = null;
}
}
$factor = 8;
$zoom = $zoom - 1;
for ($k = 0; $k < $ny / $factor; $k++) {
for ($i = 0; $i < $nx / $factor; $i++) {
$im2 = imagecreatetruecolor(512, 512);
imagecopyresized($im2, $im, 0, 0, $i * $kusokX * $factor, $k * $kusokY * $factor, 512, 512, $kusokX * $factor, $kusokY * $factor);
//imageInterlace($im2, 1);
imagejpeg($im2, "{$temp_dir}/" . "1_{$zoom}_{$i}_{$k}_.jpeg", 90);
$im2 = null;
}
}
$im2 = imagecreatetruecolor(512, 512);
imagecopyresized($im2, $im, 0, 0, 0, 0, 512, 256, $imSX, $imSY);
imagejpeg($im2, "{$temp_dir}/" . "1_0_0_0_.jpeg", 90);
}
示例10: getColors
/**
* Отримати кольора
* @return array
*/
public function getColors()
{
$image = imageCreateFromJpeg($this->address);
$color = imagecolorat($image, 10, 15);
$colors = imagecolorsforindex($image, $color);
array_pop($colors);
return $colors;
}
示例11: read
/**
* Read a jpg image from file
* @param File file of the image
* @return resource internal PHP image resource of the file
*/
public function read(File $file)
{
$this->checkIfReadIsPossible($file, $this->supportedExtensions);
$image = imageCreateFromJpeg($file->getAbsolutePath());
if ($image === false) {
throw new ImageException($file->getPath() . ' is not a valid JPG image');
}
return $image;
}
示例12: __construct
public function __construct($uploaded_img_name, $save_path, $name)
{
$this->_save_path = $save_path;
if (!is_dir($this->_save_path)) {
mkdir($this->_save_path, 0777);
}
$this->_new_img_name = $name . '.jpg';
$this->_orig_img = imageCreateFromJpeg($uploaded_img_name);
$this->w = imagesx($this->_orig_img);
$this->h = imagesy($this->_orig_img);
}
示例13: loadFile
/**
* @see \wcf\system\image\adapter\IImageAdapter::loadFile()
*/
public function loadFile($file)
{
list($this->width, $this->height, $this->type) = getImageSize($file);
switch ($this->type) {
case IMAGETYPE_GIF:
$this->image = imageCreateFromGif($file);
break;
case IMAGETYPE_JPEG:
$this->image = imageCreateFromJpeg($file);
break;
case IMAGETYPE_PNG:
$this->image = imageCreateFromPng($file);
break;
default:
throw new SystemException("Could not read image '" . $file . "', format is not recognized.");
break;
}
}
示例14: loadImage
function loadImage($path)
{
if ($this->image) {
imagedestroy($this->image);
}
$img_sz = getimagesize($path);
switch ($img_sz[2]) {
case 1:
$this->image_type = "GIF";
if (!($this->image = imageCreateFromGif($path))) {
return FALSE;
} else {
return TRUE;
}
break;
case 2:
$this->image_type = "JPG";
if (!($this->image = imageCreateFromJpeg($path))) {
return FALSE;
} else {
return TRUE;
}
break;
case 3:
$this->image_type = "PNG";
if (!($this->image = imageCreateFromPng($path))) {
return FALSE;
} else {
return TRUE;
}
break;
case 4:
$this->image_type = "SWF";
if (!($this->image = imageCreateFromSwf($path))) {
return FALSE;
} else {
return TRUE;
}
break;
default:
return FALSE;
}
}
示例15: actionTest
public function actionTest()
{
$i = 10;
$g = 20;
$photo = new GeneratorImageColorPalette();
// $t1 = $photo->getImageColor('https://scontent.cdninstagram.com/hphotos-xfa1/t51.2885-15/s150x150/e35/11820536_519767031505386_1692984693_n.jpg',$i,$g);
// $t2 = $photo->getImageColor('https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s150x150/e35/11850151_147906375552698_1188110438_n.jpg',$i,$g);
// $t3 = $photo->getImageColor('https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s150x150/e35/11850151_147906375552698_1188110438_n.jpg',$i,$g);
// $t4 = $photo->getImageColor('https://scontent.cdninstagram.com/hphotos-xfp1/t51.2885-15/s150x150/e35/1389277_898236996891339_792704999_n.jpg',$i,$g);
// $t5 = $photo->getImageColor('https://scontent.cdninstagram.com/hphotos-xfa1/t51.2885-15/s150x150/e35/11375282_1475416576086732_1622940988_n.jpg',$i,$g);
$t = 'https://scontent.cdninstagram.com/hphotos-xfa1/t51.2885-15/s150x150/e35/11375282_1475416576086732_1622940988_n.jpg';
// $t = 'https://scontent.cdninstagram.com/hphotos-xfa1/t51.2885-15/s150x150/e35/11820536_519767031505386_1692984693_n.jpg';
// $t = 'https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s150x150/e35/11850151_147906375552698_1188110438_n.jpg';
$t = 'https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s150x150/e15/11325634_802930826488058_1599582105_n.jpg';
$t = 'https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s150x150/e15/11382549_922947047728394_1720425873_n.jpg';
$t = 'https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s150x150/e15/11287495_1640746426170859_1360888926_n.jpg';
$t = 'https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s150x150/e15/11358192_686709151434224_172548493_n.jpg';
// $t = 'https://scontent.cdninstagram.com/hphotos-xfa1/t51.2885-15/s150x150/e35/11820536_519767031505386_1692984693_n.jpg';
// $t = 'https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s150x150/e35/c216.0.648.648/11950711_476949739149891_1670913693_n.jpg';
//Загрузка JPG-изображения из файла Image.jpg
$image = imageCreateFromJpeg($t);
//Возвращаем цвет пикселя с координатами (10, 15) на изображении $image
$color = imagecolorat($image, 10, 15);
$colors = imagecolorsforindex($image, $color);
//Получаем составляющие цвета (red, green, blue)
// $r = ($color >> 16) & 0xFF;
// $g = ($color >> 8) & 0xFF;
// $b = $color & 0xFF;
//Выводим результат
// echo $r."<br />";
// echo $g."<br />";
// echo $b."<br />";
//
var_dump($colors);
var_dump(max(array(5 => 88, 99 => 55)));
//Освобождаем ресурсы сервера
// imageDestroy($image);
$t = new Color($t);
echo $t->getDominantColor();
}