本文整理汇总了PHP中ImageCreateFromJpeg函数的典型用法代码示例。如果您正苦于以下问题:PHP ImageCreateFromJpeg函数的具体用法?PHP ImageCreateFromJpeg怎么用?PHP ImageCreateFromJpeg使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ImageCreateFromJpeg函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _addWaterMark
/**
* Agrega una marca de agua a la foto
* @param string $absolutePath
*/
private function _addWaterMark($absolutePath)
{
$DOC_ROOT = $this->_CI->input->server('DOCUMENT_ROOT') . "/";
if (FALSE === is_file($absolutePath)) {
return FALSE;
}
switch (TRUE) {
case stristr($absolutePath, 'jpg'):
$photoImage = ImageCreateFromJpeg("{$absolutePath}");
break;
case stristr($absolutePath, 'gif'):
$photoImage = ImageCreateFromGIF("{$absolutePath}");
break;
case stristr($absolutePath, 'png'):
$photoImage = ImageCreateFromPNG("{$absolutePath}");
break;
}
ImageAlphaBlending($photoImage, true);
// Añadimos aquà el fichero de marca de agua.
$logoImage = ImageCreateFromPNG($DOC_ROOT . "assets/imagenes/marca_agua_telam.png");
$logoW = ImageSX($logoImage);
$logoH = ImageSY($logoImage);
$tamanox = imagesx($photoImage);
$ubicacionX = ($tamanox - $logoW) / 2;
$tamanoy = imagesy($photoImage);
$ubicacionY = ($tamanoy - $logoH) / 2;
ImageCopy($photoImage, $logoImage, $ubicacionX, $ubicacionY, 0, 0, $logoW, $logoH);
imagejpeg($photoImage, $absolutePath);
ImageDestroy($photoImage);
ImageDestroy($logoImage);
}
示例2: resize
function resize($src, $dest, $new_width, $new_height)
{
if (!file_exists($src)) {
die('No source to sample picture: ' . $src);
}
$image_big = ImageCreateFromJpeg($src);
$height = imageSY($image_big);
$width = imageSX($image_big);
$ratio_hor = 1;
$ratio_ver = 1;
if ($height > $new_height) {
$ratio_ver = $new_height / $height;
}
if ($width > $new_width) {
$ratio_hor = $new_width / $width;
}
$ratio = min($ratio_hor, $ratio_ver);
$new_height = round($height * $ratio);
$new_width = round($width * $ratio);
$image_redim = imagecreatetruecolor($new_width, $new_height);
#l'apercu de l'image (plus petite)
imagecopyresampled($image_redim, $image_big, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg($image_redim, $dest, IMAGE_REDUCED_QUALITY);
#ecrit l'apercu sur le disque
}
示例3: SetVar
function SetVar($srcFile, $echoType)
{
if (!file_exists($srcFile)) {
echo '源图片文件不存在!';
exit;
}
$this->srcFile = $srcFile;
$this->echoType = $echoType;
$info = "";
$data = GetImageSize($this->srcFile, $info);
switch ($data[2]) {
case 1:
if (!function_exists("imagecreatefromgif")) {
echo "你的GD库不能使用GIF格式的图片,请使用Jpeg或PNG格式!<a href='javascript:go(-1);'>返回</a>";
exit;
}
$this->im = ImageCreateFromGIF($this->srcFile);
break;
case 2:
if (!function_exists("imagecreatefromjpeg")) {
echo "你的GD库不能使用jpeg格式的图片,请使用其它格式的图片!<a href='javascript:go(-1);'>返回</a>";
exit;
}
$this->im = ImageCreateFromJpeg($this->srcFile);
break;
case 3:
$this->im = ImageCreateFromPNG($this->srcFile);
break;
}
$this->srcW = ImageSX($this->im);
$this->srcH = ImageSY($this->im);
}
示例4: get_hex
function get_hex($location, $extensions = array('PNG', 'png', 'Png', 'JPG', 'jpg', 'Jpg', 'JPEG', 'jpeg', 'Jpeg', 'GIF', 'gif', 'Gif'), $postvar = "myimage", $getvar = "imgclix")
{
if (isset($_GET[$getvar])) {
foreach ($extensions as $var) {
if (file_exists($location . str_replace(array("..", ".", $var), '', html_entity_decode($_GET[$getvar])) . "." . $var)) {
if (stristr($var, 'png')) {
$im = ImageCreateFromPng($location . str_replace(array("..", ".", $var), '', html_entity_decode($_GET[$getvar])) . "." . $var);
} elseif (stristr($var, 'gif')) {
$im = ImageCreateFromGIF($location . str_replace(array("..", ".", $var), '', html_entity_decode($_GET[$getvar])) . "." . $var);
} elseif (stristr($var, 'jpg') || stristr($var, 'jpeg')) {
$im = ImageCreateFromJpeg($location . str_replace(array("..", ".", $var), '', html_entity_decode($_GET[$getvar])) . "." . $var);
} else {
return FALSE;
}
$rgb = ImageColorAt($im, $_POST[$postvar . '_x'], $_POST[$postvar . '_y']);
$rgb = imagecolorsforindex($im, $rgb);
$hex = sprintf('#%02X%02X%02X', $rgb['red'], $rgb['green'], $rgb['blue']);
break;
}
}
} else {
return FALSE;
}
if (!isset($hex) || $hex == '') {
return FALSE;
}
return $hex;
}
示例5: action_add_image
public function action_add_image()
{
if (count($_FILES)) {
$pathinfo = pathinfo($_FILES['file']['name']);
if (strtolower($pathinfo['extension']) == 'jpg') {
$filename = URL::title($pathinfo['filename']) . '.jpg';
$new_filename = $filename;
$counter = 1;
while (!Content_Image::image_name_available($new_filename)) {
$new_filename = substr($filename, 0, strlen($filename) - 4) . '_' . $counter . '.jpg';
$counter++;
}
if (move_uploaded_file($_FILES['file']['tmp_name'], APPPATH . '/user_content/images/' . $new_filename)) {
$gd_img_object = ImageCreateFromJpeg(Kohana::$config->load('user_content.dir') . '/images/' . $new_filename);
$details = array('width' => array(imagesx($gd_img_object)), 'height' => array(imagesy($gd_img_object)));
foreach ($_POST['tag'] as $nr => $tag_name) {
if ($tag_name != '') {
if (!isset($details[$tag_name])) {
$details[$tag_name] = array();
}
$details[$tag_name][] = $_POST['tag_value'][$nr];
}
}
Content_Image::new_image($new_filename, $details);
$this->add_message('Image "' . $new_filename . '" added');
} else {
$this->add_error('Unknown error uploading image');
}
} else {
$this->add_error('Image must be of jpeg type (file extension .jpg)');
}
}
}
示例6: SetVar
function SetVar($srcFile, $echoType)
{
$this->srcFile = $srcFile;
$this->echoType = $echoType;
$info = '';
$data = GetImageSize($this->srcFile, $info);
switch ($data[2]) {
case 1:
if (!function_exists('imagecreatefromgif')) {
exit;
}
$this->im = ImageCreateFromGIF($this->srcFile);
break;
case 2:
if (!function_exists('imagecreatefromjpeg')) {
exit;
}
$this->im = ImageCreateFromJpeg($this->srcFile);
break;
case 3:
$this->im = ImageCreateFromPNG($this->srcFile);
break;
}
$this->srcW = ImageSX($this->im);
$this->srcH = ImageSY($this->im);
}
示例7: ImageResize
function ImageResize($srcFile, $toW, $toH, $toFile = "")
{
if ($toFile == "") {
$toFile = $srcFile;
}
$info = "";
$data = GetImageSize($srcFile, $info);
switch ($data[2]) {
case 1:
if (!function_exists("imagecreatefromgif")) {
echo "你的GD库不能使用GIF格式的图片,请使用Jpeg或PNG格式!<a href='javascript:go(-1);'>返回</a>";
exit;
}
$im = ImageCreateFromGIF($srcFile);
break;
case 2:
if (!function_exists("imagecreatefromjpeg")) {
echo "你的GD库不能使用jpeg格式的图片,请使用其它格式的图片!<a href='javascript:go(-1);'>返回</a>";
exit;
}
$im = ImageCreateFromJpeg($srcFile);
break;
case 3:
$im = ImageCreateFromPNG($srcFile);
break;
}
$srcW = ImageSX($im);
$srcH = ImageSY($im);
$toWH = $toW / $toH;
$srcWH = $srcW / $srcH;
if ($toWH <= $srcWH) {
$ftoW = $toW;
$ftoH = $ftoW * ($srcH / $srcW);
} else {
$ftoH = $toH;
$ftoW = $ftoH * ($srcW / $srcH);
}
if ($srcW > $toW || $srcH > $toH) {
if (function_exists("imagecreatetruecolor")) {
@($ni = ImageCreateTrueColor($ftoW, $ftoH));
if ($ni) {
ImageCopyResampled($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH);
} else {
$ni = ImageCreate($ftoW, $ftoH);
ImageCopyResized($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH);
}
} else {
$ni = ImageCreate($ftoW, $ftoH);
ImageCopyResized($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH);
}
if (function_exists('imagejpeg')) {
ImageJpeg($ni, $toFile);
} else {
ImagePNG($ni, $toFile);
}
ImageDestroy($ni);
}
ImageDestroy($im);
}
示例8: pcs_href_image
function pcs_href_image($src_path)
{
$strRet = DIR_WS_IMAGES . 'pcs_images/' . basename($src_path) . '_' . MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT . '_' . MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH . '_' . MODULE_ADDONS_PCSLIDESHOW_IMAGE_QUALITY . '.jpg';
#This will be the filename of the resized image.
if (!file_exists($strRet)) {
#Create the file if it does not exist
#check to see if source file exists
if (!file_exists($src_path)) {
return 'error1';
#check to see if source file is readable
} elseif (!is_readable($src_path)) {
return 'error2';
}
#check if gif
if (stristr(strtolower($src_path), '.gif')) {
$oldImage = ImageCreateFromGif($src_path);
} elseif (stristr(strtolower($src_path), '.jpg') || stristr(strtolower($src_path), '.jpeg')) {
$oldImage = ImageCreateFromJpeg($src_path);
} elseif (stristr(strtolower($src_path), '.png')) {
$oldImage = ImageCreateFromPng($src_path);
} else {
return 'error3';
}
#Create the new image
if (function_exists("ImageCreateTrueColor")) {
$newImage = ImageCreateTrueColor(MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH, MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT);
} else {
$newImage = ImageCreate(MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH, MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT);
}
$backgroundColor = imagecolorallocate($newImage, 255, 255, 255);
imagefill($newImage, 0, 0, $backgroundColor);
#calculate the rezised image's dimmensions
if (imagesx($oldImage) > MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH || imagesy($oldImage) > MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT) {
#Resize image
if (imagesx($oldImage) / MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH > imagesy($oldImage) / MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT) {
#Width is leading in beeing to large
$newWidth = (int) MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH;
$newHeight = (int) MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH / imagesx($oldImage) * imagesy($oldImage);
} else {
#Height is leading in beeing to large
$newHeight = (int) MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT;
$newWidth = (int) MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT / imagesy($oldImage) * imagesx($oldImage);
}
} else {
#Don't rezise image
$newWidth = imagesx($oldImage);
$newHeight = imagesy($oldImage);
}
#Copy the old image onto the new image
ImageCopyResampled($newImage, $oldImage, MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_WIDTH / 2 - $newWidth / 2, MODULE_ADDONS_PCSLIDESHOW_MAX_IMAGE_HEIGHT / 2 - $newHeight / 2, 0, 0, $newWidth, $newHeight, imagesx($oldImage), imagesy($oldImage));
imagejpeg($newImage, $strRet, MODULE_ADDONS_PCSLIDESHOW_IMAGE_QUALITY);
#save the image
imagedestroy($oldImage);
#Free Memory
imagedestroy($newImage);
#Free memory
}
return $strRet;
}
示例9: ResizeImage
function ResizeImage($Filename, $Thumbnail, $Size)
{
$Path = pathinfo($Filename);
$Extension = $Path['extension'];
$ImageData = @GetImageSize($Filename);
$Width = $ImageData[0];
$Height = $ImageData[1];
if ($Width >= $Height and $Width > $Size) {
$NewWidth = $Size;
$NewHeight = $Size / $Width * $Height;
} elseif ($Height >= $Width and $Height > $Size) {
$NewWidth = $Size / $Height * $Width;
$NewHeight = $Size;
} else {
$NewWidth = $Width;
$NewHeight = $Height;
}
$NewImage = @ImageCreateTrueColor($NewWidth, $NewHeight);
if (preg_match('/^gif$/i', $Extension)) {
$Image = @ImageCreateFromGif($Filename);
} elseif (preg_match('/^png$/i', $Extension)) {
$Image = @ImageCreateFromPng($Filename);
} else {
$Image = @ImageCreateFromJpeg($Filename);
}
if ($ImageData[2] == IMAGETYPE_GIF or $ImageData[2] == IMAGETYPE_PNG) {
$TransIndex = imagecolortransparent($Image);
// If we have a specific transparent color
if ($TransIndex >= 0) {
// Get the original image's transparent color's RGB values
$TransColor = imagecolorsforindex($Image, $TransIndex);
// Allocate the same color in the new image resource
$TransIndex = imagecolorallocate($NewImage, $TransColor['red'], $TransColor['green'], $TransColor['blue']);
// Completely fill the background of the new image with allocated color.
imagefill($NewImage, 0, 0, $TransIndex);
// Set the background color for new image to transparent
imagecolortransparent($NewImage, $TransIndex);
} elseif ($ImageData[2] == IMAGETYPE_PNG) {
// Turn off transparency blending (temporarily)
imagealphablending($NewImage, false);
// Create a new transparent color for image
$color = imagecolorallocatealpha($NewImage, 0, 0, 0, 127);
// Completely fill the background of the new image with allocated color.
imagefill($NewImage, 0, 0, $color);
// Restore transparency blending
imagesavealpha($NewImage, true);
}
}
@ImageCopyResampled($NewImage, $Image, 0, 0, 0, 0, $NewWidth, $NewHeight, $Width, $Height);
if (preg_match('/^gif$/i', $Extension)) {
@ImageGif($NewImage, $Thumbnail);
} elseif (preg_match('/^png$/i', $Extension)) {
@ImagePng($NewImage, $Thumbnail);
} else {
@ImageJpeg($NewImage, $Thumbnail);
}
@chmod($Thumbnail, 0644);
}
示例10: createFromFile
public static function createFromFile($filename, $mime_type, $objAlbum)
{
$objPicture = new clsPicture();
/* Decide which incoming mime type it is. */
switch ($mime_type) {
case 'image/jpeg':
$img = ImageCreateFromJpeg($filename);
break;
case 'image/png':
$img = ImageCreateFromPng($filename);
break;
case 'image/gif':
$img = ImageCreateFromGif($filename);
break;
default:
return 'image_filetype';
}
list($intWidth, $intHeight) = getImageSize($filename);
$intMaxWidth = $objAlbum->get('max_width');
$intMaxHeight = $objAlbum->get('max_height');
if ($intMaxWidth <= 0) {
$intMaxWidth = DEFAULT_X;
}
if ($intMaxHeight <= 0) {
$intMaxHeight = DEFAULT_Y;
}
if ($intWidth > $intMaxWidth || $intHeight > $intMaxHeight) {
/* Check whether the image needs to be resized vertically or horizonally more. */
if ($intWidth / $intMaxWidth > $intHeight / $intMaxHeight) {
/* Right-left needs to have priority. */
$ratio = $intMaxWidth / $intWidth;
} else {
/* Up-down needs to have priority. */
$ratio = $intMaxHeight / $intHeight;
}
$intNewWidth = $intWidth * $ratio;
$intNewHeight = $intHeight * $ratio;
$imgNew = @ImageCreateTrueColor($intNewWidth, $intNewHeight);
if (!@ImageCopyResized($imgNew, $img, 0, 0, 0, 0, $intNewWidth, $intNewHeight, $intWidth, $intHeight)) {
return "image_noresize";
}
$intWidth = $intNewWidth;
$intHeight = $intNewHeight;
ImageDestroy($img);
$img = $imgNew;
}
/* This has to be done before setImage() because setImage() needs data from the album. */
$objPicture->set('album_id', $objAlbum->get('id'));
$result = $objPicture->setImage($img);
ImageDestroy($img);
if ($result) {
return $result;
}
$objPicture->set('width', $intWidth);
$objPicture->set('height', $intHeight);
$objPicture->save();
return $objPicture;
}
示例11: resizeJpeg
/**
*
* @throws Sitengine_Exception
*
*/
public static function resizeJpeg($inFile, $outFile, $length, $method, $mode = 0644, $quality = 50)
{
$size = getimagesize($inFile);
if (!$size) {
throw new Sitengine_Exception('jpg could not be opened');
}
if ($size[2] != 2) {
throw new Sitengine_Exception('image is not a jpg');
}
if (!preg_match('/^\\d{1,3}$/', $quality)) {
$quality = 50;
}
if ($quality < 0 || $quality > 100) {
$quality = 50;
}
switch ($method) {
case 'width':
$width = $length;
$height = self::calcHeight($size[0], $size[1], $length);
break;
case 'height':
$width = self::calcWidth($size[0], $size[1], $length);
$height = $length;
break;
default:
if ($size[0] > $size[1]) {
$width = $length;
$height = self::calcHeight($size[0], $size[1], $length);
} else {
$width = self::calcWidth($size[0], $size[1], $length);
$height = $length;
}
break;
}
$inRid = ImageCreateFromJpeg($inFile);
if (!$inRid) {
throw new Sitengine_Exception('jpg processing error');
}
$outRid = imagecreatetruecolor($width, $height);
if (!$outRid) {
throw new Sitengine_Exception('jpg processing error');
}
$copy = imagecopyresampled($outRid, $inRid, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
if (!$copy) {
throw new Sitengine_Exception('jpg processing error');
}
$image = imagejpeg($outRid, $outFile, $quality);
if (!$image) {
throw new Sitengine_Exception('jpg processing error');
}
chmod($outFile, $mode);
$stats = stat($outFile);
return array('mime' => 'image/jpeg', 'size' => $stats['size'], 'width' => $width, 'height' => $height);
}
示例12: createImage
function createImage()
{
$imageString = $_GET['type'];
$length = strlen($imageString);
$max = 6;
$x = ($max - $length) * 7;
$image = ImageCreateFromJpeg("../images/file_manager_file.jpg");
$black = ImageColorAllocate($image, 0, 0, 0);
ImageString($image, 6, $x, 45, $imageString, $black);
header("Content-Type: image/jpeg");
ImageJpeg($image);
ImageDestroy($image);
}
示例13: createimageByType
private function createimageByType($data, $file)
{
if ($data['type'] === "image/jpeg") {
$image = ImageCreateFromJpeg($file);
}
if ($data['type'] === "image/png") {
$image = ImageCreateFromPng($file);
}
if ($data['type'] === "image/gif") {
$image = ImageCreateFromGif($file);
}
return $image;
}
示例14: create_image_container
private function create_image_container($file, $type)
{
$path = $this->config->item("upload_dir");
if (strtolower($type) === ".jpg" || strtolower($type) === ".jpeg") {
$image = ImageCreateFromJpeg($path . $file . $type);
} elseif (strtolower($type) === ".png") {
$image = ImageCreateFromPng($path . $file . $type);
} elseif (strtolower($type) === ".gif") {
$image = ImageCreateFromGif($path . $file . $type);
} else {
$image = false;
}
return $image;
}
示例15: grip
function grip($K, $OldImageFile, $NewImageFile)
{
$WidthAndHeight = getimagesize($OldImageFile);
$Width = $WidthAndHeight[0];
$Height = $WidthAndHeight[1];
$NewWidth = ceil($Width * $K);
$NewHeight = ceil($Height * $K);
$src = ImageCreateFromJpeg($OldImageFile);
$dst = imagecreatetruecolor($NewWidth, $NewHeight);
ImageCopyResampled($dst, $src, 0, 0, 0, 0, $NewWidth, $NewHeight, $Width, $Height);
ImageJpeg($dst, $NewImageFile, 80);
ImageDestroy($src);
ImageDestroy($dst);
}