本文整理汇总了PHP中ImageJpeg函数的典型用法代码示例。如果您正苦于以下问题:PHP ImageJpeg函数的具体用法?PHP ImageJpeg怎么用?PHP ImageJpeg使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ImageJpeg函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: kicsinyites
function kicsinyites($forras, $kimenet, $max)
{
if (!isset($max)) {
$max = 120;
}
# maximum size of 1 side of the picture.
$src_img = ImagecreateFromJpeg($forras);
$oh = imagesy($src_img);
# original height
$ow = imagesx($src_img);
# original width
$new_h = $oh;
$new_w = $ow;
if ($oh > $max || $ow > $max) {
$r = $oh / $ow;
$new_h = $oh > $ow ? $max : $max * $r;
$new_w = $new_h / $r;
}
// note TrueColor does 256 and not.. 8
$dst_img = ImageCreateTrueColor($new_w, $new_h);
/* imageantialias($dst_img, true); */
/* ImageCopyResized($dst_img, $src_img, 0,0,0,0, $new_w, $new_h, ImageSX($src_img), ImageSY($src_img)); */
ImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, ImageSX($src_img), ImageSY($src_img));
ImageJpeg($dst_img, "{$kimenet}");
}
示例2: create_image
function create_image()
{
//generate a random string
$md5_hash = md5(rand(0, 999));
//make it 5 characters long
$security_code = substr($md5_hash, 15, 5);
//Storing the security code in the session
$_SESSION["security_code"] = $security_code;
//Create the image
$image = @imagecreatefromjpeg("images/static.jpg");
//Making the font color
$black = ImageColorAllocate($image, 0, 0, 0);
//Make the background black
//ImageFill($image, 0, 0, $bgImg);
//Set some variables for positioning and font-size, "5" is the largest I could get to work
$vPos = 10;
$hPos = 28;
$fontSize = 5;
ImageString($image, $fontSize, $hPos, $vPos, $security_code, $black);
//Tell the browser what kind of file this is
header("Content-Type: image/jpeg");
//Output image as a jpeg
ImageJpeg($image);
//Free up stuff
ImageDestroy($image);
}
示例3: makeThumb1
/**
* 把图片生成缩略图1
* @param string $srcFile 源文件
* @param string $dstFile 目标文件
* @param int $dstW 目标图片宽度
* @param int $dstH 目标文件高度
* @param string $dstFormat 目标文件生成的格式, 有png和jpg两种格式
* @return 错误返回错误对象
*/
public static function makeThumb1($srcFile, $dstFile, $dstW, $dstH, $dstFormat = "png")
{
//打开图片
$data = GetImageSize($srcFile, &$info);
switch ($data[2]) {
case 1:
$im = @ImageCreateFromGIF($srcFile);
break;
case 2:
$im = @imagecreatefromjpeg($srcFile);
break;
case 3:
$im = @ImageCreateFromPNG($srcFile);
break;
}
if (!$im) {
throw new TM_Exception(__CLASS__ . ": Create image failed");
}
//设定图片大小
$srcW = ImageSX($im);
$srcH = ImageSY($im);
$ni = ImageCreate($dstW, $dstH);
ImageCopyResized($ni, $im, 0, 0, 0, 0, $dstW, $dstH, $srcW, $srcH);
//生成指定格式的图片
if ($dstFormat == "png") {
imagepng($ni, $dstFile);
} elseif ($dstFormat == "jpg") {
ImageJpeg($ni, $dstFile);
} else {
imagepng($ni, $dstFile);
}
}
示例4: ResizeImage
function ResizeImage($im, $maxwidth, $maxheight, $name)
{
//取得当前图片大小
$width = imagesx($im);
$height = imagesy($im);
//生成缩略图的大小
if ($width > $maxwidth || $height > $maxheight) {
$widthratio = $maxwidth / $width;
$heightratio = $maxheight / $height;
if ($widthratio < $heightratio) {
$ratio = $widthratio;
} else {
$ratio = $heightratio;
}
$newwidth = $width * $ratio;
$newheight = $height * $ratio;
if (function_exists("imagecopyresampled")) {
$newim = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
} else {
$newim = imagecreate($newwidth, $newheight);
imagecopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}
ImageJpeg($newim, $name);
ImageDestroy($newim);
} else {
ImageJpeg($im, $name);
}
}
示例5: createnewpicture
private function createnewpicture()
{
$local = $this->path_two . $this->file['name'];
move_uploaded_file($this->file['tmp_name'], $local);
$filename = $this->file['tmp_name'] . "/" . $this->file['name'];
$this->location = $this->path . "/" . $this->file['name'];
switch ($this->file['type']) {
case 'image/jpeg':
$src = imagecreatefromjpeg($local);
break;
case 'image/png':
$src = imagecreatefrompng($local);
break;
case 'image/gif':
$src = imagecreatefromgif($local);
break;
default:
break;
}
$sx = imagesx($src);
$sy = imagesy($src);
$new_image = imagecreatetruecolor($this->newwidth, $this->newheight);
if (imagecopyresized($new_image, $src, 0, 0, 0, 0, $this->newwidth, $this->newheight, $sx, $sy)) {
if (ImageJpeg($new_image, $this->location) || Imagegif($new_image, $this->location) || Imagepng($new_image, $this->location)) {
//imagejpeg($this->location);
return true;
}
} else {
return false;
}
}
示例6: newimg
function newimg()
{
//改变后的图象的比例
$resize_ratio = $this->resize_width / $this->resize_height;
//实际图象的比例
$ratio = $this->width / $this->height;
if ($this->cut == "1") {
if ($ratio >= $resize_ratio) {
$newimg = imagecreatetruecolor($this->resize_width, $this->resize_height);
imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, $this->resize_height, $this->height * $resize_ratio, $this->height);
ImageJpeg($newimg, $this->dstimg);
}
if ($ratio < $resize_ratio) {
$newimg = imagecreatetruecolor($this->resize_width, $this->resize_height);
imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, $this->resize_height, $this->width, $this->width / $resize_ratio);
ImageJpeg($newimg, $this->dstimg);
}
} else {
if ($ratio >= $resize_ratio) {
$newimg = imagecreatetruecolor($this->resize_width, $this->resize_width / $ratio);
imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, $this->resize_width / $ratio, $this->width, $this->height);
ImageJpeg($newimg, $this->dstimg);
}
if ($ratio < $resize_ratio) {
$newimg = imagecreatetruecolor($this->resize_height * $ratio, $this->resize_height);
imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_height * $ratio, $this->resize_height, $this->width, $this->height);
ImageJpeg($newimg, $this->dstimg);
}
}
}
示例7: draw_captcha
function draw_captcha($security_code)
{
//Set the image width and height
$width = 100;
$height = 25;
//Create the image resource
$image = ImageCreate($width, $height);
if (function_exists('imageantialias')) {
imageantialias($image, true);
}
//We are making three colors, white, black and gray
$white = ImageColorAllocate($image, 255, 255, 255);
$black = ImageColorAllocate($image, 15, 50, 15);
$grey = ImageColorAllocate($image, 204, 204, 204);
$ellipsec = ImageColorAllocate($image, 0, 100, 60);
//Make the background black
ImageFill($image, 0, 0, $black);
imagefilledellipse($image, 56, 15, 30, 17, $ellipsec);
//Add randomly generated string in white to the image
ImageString($image, 5, 30, 4, $security_code, $white);
//Throw in some lines to make it a little bit harder for any bots to break
ImageRectangle($image, 0, 0, $width - 1, $height - 1, $grey);
imageline($image, 0, $height / 2 + 3, $width, $height / 2 + 5, $grey);
imageline($image, $width / 2 - 14, 0, $width / 2 + 7, $height, $grey);
//Tell the browser what kind of file is come in
header("Content-Type: image/jpeg");
//Output the newly created image in jpeg format
ImageJpeg($image);
//Free up resources
ImageDestroy($image);
}
示例8: display
/**
* Generates a random captcha image
*
**/
function display($cachable = false, $urlparams = false)
{
// @TODO: Run some cleaning query here to clear the database.
JTable::addIncludePath(DISCUSS_TABLES);
$id = JRequest::getInt('captcha-id', '');
$captcha = DiscussHelper::getTable('Captcha');
// clearing the oudated keys.
$captcha->clear();
// load the captcha records.
$captcha->load($id);
if (!$captcha->id) {
return false;
}
// @task: Generate a very random integer and take only 5 chars max.
$hash = JString::substr(md5(rand(0, 9999)), 0, 5);
$captcha->response = $hash;
$captcha->store();
// Captcha width and height
$width = 100;
$height = 20;
$image = ImageCreate($width, $height);
$white = ImageColorAllocate($image, 255, 255, 255);
$black = ImageColorAllocate($image, 0, 0, 0);
$gray = ImageColorAllocate($image, 204, 204, 204);
ImageFill($image, 0, 0, $white);
ImageString($image, 5, 30, 3, $hash, $black);
ImageRectangle($image, 0, 0, $width - 1, $height - 1, $gray);
imageline($image, 0, $height / 2, $width, $height / 2, $gray);
imageline($image, $width / 2, 0, $width / 2, $height, $gray);
header('Content-type: image/jpeg');
ImageJpeg($image);
ImageDestroy($image);
exit;
}
示例9: generate
/**
* Generates the captcha image
*
* @since 4.0
* @access public
* @param string
* @return
*/
public function generate()
{
$id = $this->input->get('id', '', 'int');
// Load up the captcha object
$captcha = EB::table('Captcha');
// Clear outdated keys
$captcha->clear();
// load the captcha records.
$captcha->load($id);
if (!$captcha->id) {
return false;
}
// @task: Generate a very random integer and take only 5 chars max.
$hash = JString::substr(md5(rand(0, 9999)), 0, 5);
$captcha->response = $hash;
$captcha->store();
// Captcha width and height
$width = 100;
$height = 20;
$image = ImageCreate($width, $height);
$white = ImageColorAllocate($image, 255, 255, 255);
$black = ImageColorAllocate($image, 0, 0, 0);
$gray = ImageColorAllocate($image, 204, 204, 204);
ImageFill($image, 0, 0, $white);
ImageString($image, 5, 30, 3, $hash, $black);
ImageRectangle($image, 0, 0, $width - 1, $height - 1, $gray);
imageline($image, 0, $height / 2, $width, $height / 2, $gray);
imageline($image, $width / 2, 0, $width / 2, $height, $gray);
header('Content-type: image/jpeg');
ImageJpeg($image);
ImageDestroy($image);
exit;
}
示例10: create_image
function create_image()
{
//Let's generate a totally random string using md5
$md5_hash = md5(rand(0, 999));
//We don't need a 32 character long string so we trim it down to 5
$security_code = substr($md5_hash, 15, 5);
//Set the session to store the security code
$_SESSION["captchaCode"] = $security_code;
//Set the image width and height
$width = 100;
$height = 20;
//Create the image resource
$image = ImageCreate($width, $height);
//We are making three colors, white, black and gray
$white = ImageColorAllocate($image, 255, 255, 255);
$black = ImageColorAllocate($image, 0, 0, 0);
$grey = ImageColorAllocate($image, 204, 204, 204);
//Make the background black
ImageFill($image, 0, 0, $black);
//Add randomly generated string in white to the image
ImageString($image, 3, 30, 3, $security_code, $white);
//Throw in some lines to make it a little bit harder for any bots to break
ImageRectangle($image, 0, 0, $width - 1, $height - 1, $grey);
imageline($image, 0, $height / 2, $width, $height / 2, $grey);
imageline($image, $width / 2, 0, $width / 2, $height, $grey);
//Tell the browser what kind of file is come in
header("Content-Type: image/jpeg");
//Output the newly created image in jpeg format
ImageJpeg($image);
//Free up resources
ImageDestroy($image);
}
示例11: create_image
function create_image($string_captcha, $width = 130, $height = 35)
{
//Let's generate a totally random string using md5
// $md5_hash = md5(rand(0,999));
//We don't need a 32 character long string so we trim it down to 5
// $security_code = substr($md5_hash, 15, 5);
$security_code = $string_captcha;
/* ********************************************
Use this part if you need to Set the session
to store the security code */
$_SESSION['security_code'] = $security_code;
$CodeInd = 0;
$arrSecCode = array();
$chars = preg_split('//', $security_code);
$security_code = implode(" ", $chars);
//Set the image width and height
//$width = 130;
//$height = 35;
//Create the image resource
$image = ImageCreate($width, $height);
//We are making three colors, white, black and gray
$arrB = array(0, 255, 129, 10, 48, 200, 186);
$arrR = array(0, 255, 129, 111, 48, 210, 126);
$arrG = array(0, 205, 139, 110, 48, 5, 186);
$black = ImageColorAllocate($image, $arrR[rand(0, 6)], $arrG[rand(0, 6)], $arrB[rand(0, 6)]);
$white = ImageColorAllocate($image, 255, 255, 255);
$grey = ImageColorAllocate($image, 175, 253, 253);
//Make the background black
ImageFill($image, 0, 0, $black);
$font = 5;
$arrSel = array(1, 2, 3, 4);
$selectedNum = $arrSel[rand(0, 3)];
ImageString($image, $font, 10, 10, $security_code, $white);
//Throw in some lines to make it a little bit harder for any bots to break
ImageRectangle($image, 0, 0, $width - 1, $height - 1, $grey);
if ($selectedNum == 1) {
imageline($image, 0, $height / 2, $width, $height / 5, $grey);
imageline($image, $width / 2, 0, $width / 3, $height / 5, $grey);
imageline($image, $width / 2, 0, $width / 10, $height, $grey);
imageline($image, $width / 2, 0, $width / 10, $height / 6, $grey);
}
if ($selectedNum == 2) {
imageline($image, $width / 1, 0, $width / 6, $height, $grey);
imageline($image, 0, $height / 5, $width, $height / 8, $grey);
imageline($image, 0, $height / 5, $width / 5, $height / 8, $grey);
imageline($image, 0, $height / 3, $width, $height, $grey);
}
if ($selectedNum == 3) {
imageline($image, 0, $height, $width, 0, $grey);
imageline($image, 0, 0, $height, $height, $grey);
imageline($image, $width / 5, 0, $width / 6, $height, $grey);
imageline($image, $width / 4, 0, $width / 4, $height, $grey);
}
//Tell the browser what kind of file is come in
header("Content-Type: image/jpeg");
//Output the newly created image in jpeg format
ImageJpeg($image);
//Free up resources
ImageDestroy($image);
}
示例12: Mostrar
public static function Mostrar()
{
// La cantidad de caracteres que va a mostrar el captcha
$longitud = 5;
// Los caracteres que nuestro captcha va a considerar
$caracteres = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
// El catpcha creado
$captcha = "";
for ($i = 0; $i < $longitud; $i++) {
$captcha .= $caracteres[rand(0, strlen($caracteres) - 1)];
}
// Guardamos el catpcha en sesion para validar
$_SESSION['captcha_codigo'] = strtolower($captcha);
// Creamos la imagen
// Creamos una imagen con forma de rectangulo por las medidas definidas a continuación
$ancho = 600;
$alto = 180;
$fuente_tamano = 80;
$fuente = 'lib/captcha/font.ttf';
$img = imagecreatetruecolor($ancho, $alto);
// Agregamos el texto
$blanco = ImageColorAllocate($img, 255, 255, 255);
// BLANCO
// Coordenadas de donde va a ir el texto
$x = $fuente_tamano;
$y = $alto / 2 + 25;
// El texto blanco
imagettftext($img, $fuente_tamano, 0, $x, $y, $blanco, $fuente, $captcha);
// Generamos la imagen
header("Content-Type: image/jpeg");
ImageJpeg($img);
ImageDestroy($img);
}
示例13: capcha
function capcha($salt)
{
srand(time());
$md5_hash = md5(rand(0, 9999));
$security_code = substr($md5_hash, 25, 5);
$enc = md5($security_code . $salt);
$_SESSION['count'] = $enc;
$secure = $_SESSION['count'];
// echo "--------------------------$secure<br>";
$width = 50;
$height = 24;
$image = ImageCreate($width, $height);
$white = ImageColorAllocate($image, 255, 255, 255);
$black = ImageColorAllocate($image, 0, 100, 0);
$grey = ImageColorAllocate($image, 204, 204, 204);
ImageFill($image, 0, 0, $white);
//Add randomly generated string in white to the image
ImageString($image, 10, 4, 4, $security_code, $black);
// ImageRectangle($image,0,16,$width-1,$height-1,$grey);
imageline($image, 0, $height / 2, $width, $height / 2, $grey);
imageline($image, $width / 2, 0, $width / 2, $height, $grey);
header("Content-Type: image/jpeg");
header("Cache-Control: no-cache, must-revalidate");
ImageJpeg($image);
ImageDestroy($image);
}
示例14: 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);
}
示例15: 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);
}