本文整理汇总了PHP中imagejpeg函数的典型用法代码示例。如果您正苦于以下问题:PHP imagejpeg函数的具体用法?PHP imagejpeg怎么用?PHP imagejpeg使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagejpeg函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
}
示例2: filter
public function filter($value)
{
if (!file_exists($value)) {
throw new Zend_Filter_Exception('Image does not exist: ' . $value);
}
$image = imagecreatefromstring(file_get_contents($value));
if (false === $image) {
throw new Zend_Filter_Exception('Can\'t load image: ' . $value);
}
// find ratio to scale down to
// TODO: pass 600 as parameter in the future
$origWidth = imagesx($image);
$origHeight = imagesy($image);
$ratio = max($origWidth, $origHeight) / 600;
if ($ratio > 1) {
// img too big! create a scaled down image
$newWidth = round($origWidth / $ratio);
$newHeight = round($origHeight / $ratio);
$resized = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresampled($resized, $image, 0, 0, 0, 0, $newWidth, $newHeight, $origWidth, $origHeight);
// determine type and store to disk
$explodeResult = explode(".", $value);
$type = strtolower($explodeResult[count($explodeResult) - 1]);
$writeFunc = 'image' . $type;
if ($type == 'jpeg' || $type == 'jpg') {
imagejpeg($resized, $value, 100);
} else {
$writeFunc($resized, $value);
}
}
return $value;
}
示例3: index
public function index()
{
$code = substr(sha1(mt_rand()), 17, 6);
$this->session->set_userdata('captcha_code', $code);
$width = '120';
$height = '40';
$font = APPPATH . 'modules/contact/assets/fonts/monofont.ttf';
$font_size = $height * 0.75;
$image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
/* set the colours */
$background_color = imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 20, 40, 100);
$noise_color = imagecolorallocate($image, 100, 120, 180);
/* generate random dots in background */
for ($i = 0; $i < $width * $height / 3; $i++) {
imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color);
}
/* generate random lines in background */
for ($i = 0; $i < $width * $height / 150; $i++) {
imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color);
}
/* create textbox and add text */
$textbox = imagettfbbox($font_size, 0, $font, $code) or die('Error in imagettfbbox function');
$x = ($width - $textbox[4]) / 2;
$y = ($height - $textbox[5]) / 2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $font, $code) or die('Error in imagettftext function');
/* output captcha image to browser */
header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
}
示例4: 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;
}
示例5: 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;
}
示例6: 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);
}
}
示例7: create_thumbnail
function create_thumbnail($filename)
{
$percent = 0.1;
list($width, $height) = getimagesize("/var/www/amberandbrice.com/workspace/images/" . $filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;
$thumb = imagecreatetruecolor($newwidth, $newheight);
$ext = pathinfo($filename)['extension'];
echo "<h1>{$ext}</h1>";
switch ($ext) {
case 'jpg':
case 'jpeg':
case 'JPG':
$source = imagecreatefromjpeg("images/" . $filename);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($thumb, "./thumbs/" . $filename);
break;
case 'gif':
$source = imagecreatefromgif("images/" . $filename);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($thumb, "./thumbs/" . $filename);
break;
case 'png':
$source = imagecreatefrompng("images/" . $filename);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($thumb, "./thumbs/" . $filename);
break;
default:
die("image extension cannot be determined");
}
}
示例8: 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;
}
示例9: generate
/**
* Return captcha image
* @param number $maxChar
*/
public function generate($maxChar = 4)
{
// $characters = '23456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';
$characters = 'ABCDEFGHKMNPQRST';
$captchaText = '';
for ($i = 0; $i < $maxChar; $i++) {
$captchaText .= $characters[rand(0, strlen($characters) - 1)];
}
strtoupper(substr(md5(microtime()), 0, 7));
\Session::put('captchaHash', \Hash::make($captchaText));
$image = imagecreate(30 * $maxChar, 35);
$background = imagecolorallocatealpha($image, 255, 255, 255, 1);
$textColor = imagecolorallocatealpha($image, 206, 33, 39, 1);
$x = 5;
$y = 20;
$angle = 0;
for ($i = 0; $i < 7; $i++) {
$fontSize = 16;
$text = substr($captchaText, $i, 1);
imagettftext($image, $fontSize, $angle, $x, $y, $textColor, public_path('/fonts/LibreBaskerville/librebaskerville-regular.ttf'), $text);
$x = $x + 17 + mt_rand(1, 10);
$y = mt_rand(18, 25);
$angle = mt_rand(0, 20);
}
header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Pragma: no-cache');
header('Content-type: image/jpeg');
imagejpeg($image, null, 100);
imagedestroy($image);
}
示例10: resizer
function resizer($filename, $copypath, $MaxWidth, $MaxHeight)
{
//cesta k souboru, ktery chcete zmensit cesta, kam zmenseny soubor ulozit maximalni sirka zmenseneho obrazku //maximalni vyska zmenseneho obrazku
//zjistime puvodni velikost obrazku
list($OrigWidth, $OrigHeight) = getimagesize($filename);
//hodnota 0 v parametrech MaxWidth resp. MaxHeight znamena, ze sirka resp. vyska vysledku muze byt libovolna
if ($MaxWidth == 0) {
$MaxWidth = $OrigWidth;
}
if ($MaxHeight == 0) {
$MaxHeight = $OrigHeight;
}
//nyni vypocitam pomer zmenseni
$pw = $OrigWidth / $MaxWidth;
$ph = $OrigHeight / $MaxHeight;
if ($pw > $ph) {
$p = $pw;
} else {
$p = $ph;
}
if ($p < 1) {
$p = 1;
}
//v p ted mame pomer pro zmenseni vypocitame vysku a sirku zmenseneho obrazku
$NewWidth = (int) $OrigWidth / $p;
$NewHeight = (int) $OrigHeight / $p;
//vytvorime novy obrazek pozadovane vysky a sirky
$image_p = imagecreatetruecolor($NewWidth, $NewHeight);
//otevreme puvodni obrazek se souboru
$image = imagecreatefromjpeg($filename);
//a okopirujeme zmenseny puvodni obrazek do noveho
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $NewWidth, $NewHeight, $OrigWidth, $OrigHeight);
//a ulozime
imagejpeg($image_p, $copypath, 100);
}
示例11: render
/**
* Render the gradient to an image
**/
public function render($width, $height, $format = 'png', $filename = null)
{
$image = $this->render_gd($width, $height);
switch ($format) {
case 'jpg':
case 'jpeg':
case 'jpe':
if (empty($filename)) {
header('Content-Type: image/jpeg');
}
imagejpeg($image, $filename, 90);
break;
case 'gif':
if (empty($filename)) {
header('Content-Type: image/gif');
}
imagegif($image, $filename);
break;
case 'png':
default:
if (empty($filename)) {
header('Content-Type: image/png');
}
imagepng($image, $filename, 9);
break;
}
imagedestroy($image);
}
示例12: resizeThumbnailImage
function resizeThumbnailImage($thumb, $image, $width, $height, $start_width, $start_height, $scale)
{
$newImageWidth = ceil($width * $scale);
$newImageHeight = ceil($height * $scale);
$newImage = imagecreatetruecolor($newImageWidth, $newImageHeight);
$ext = strtolower(substr(basename($image), strrpos(basename($image), '.') + 1));
$source = '';
if ($ext == 'png') {
$source = imagecreatefrompng($image);
} elseif ($ext == 'jpg' || $ext == 'jpeg') {
$source = imagecreatefromjpeg($image);
} elseif ($ext == 'gif') {
$source = imagecreatefromgif($image);
}
imagecopyresampled($newImage, $source, 0, 0, $start_width, $start_height, $newImageWidth, $newImageHeight, $width, $height);
$ext = strtolower(substr(basename($thumb), strrpos(basename($thumb), '.') + 1));
if ($ext == 'png') {
$result = imagepng($newImage, $thumb, 0);
} elseif ($ext == 'jpg' || $ext == 'jpeg') {
$result = imagejpeg($newImage, $thumb, 90);
} elseif ($ext == 'gif') {
$result = imagegif($newImage, $thumb);
}
if (!$result) {
return false;
}
chmod($thumb, 0664);
return $thumb;
}
示例13: convertImage
function convertImage($originalImage, $outputImage, $quality = 100)
{
$myfile = fopen($outputImage, "w");
// jpg, png, gif or bmp?
$exploded = explode('.', $originalImage);
$ext = $exploded[count($exploded) - 1];
if (preg_match('/jpg|jpeg/i', $ext)) {
$imageTmp = imagecreatefromjpeg($originalImage);
} else {
if (preg_match('/png/i', $ext)) {
$imageTmp = imagecreatefrompng($originalImage);
} else {
if (preg_match('/gif/i', $ext)) {
$imageTmp = imagecreatefromgif($originalImage);
} else {
if (preg_match('/bmp/i', $ext)) {
$imageTmp = imagecreatefrombmp($originalImage);
} else {
return 0;
}
}
}
}
imagejpeg($imageTmp, $outputImage, $quality);
imagedestroy($imageTmp);
return $outputImage;
}
示例14: captcha
function captcha($width, $height, $code)
{
$font = "./font/ChalkboardBold.ttf";
$font_size = 17;
$image = imagecreate($width, $height);
$background_color = imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 20, 40, 100);
$noise_color = imagecolorallocate($image, 100, 120, 180);
for ($i = 0; $i < $width * $height / 3; $i++) {
imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color);
}
for ($i = 0; $i < $width * $height / 150; $i++) {
imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color);
}
$x = 3;
$y = 20;
imagettftext($image, $font_size, rand(-45, 45), $x, $y + rand() % 16, $text_color, $font, $code[0]);
imagettftext($image, $font_size, rand(-45, 45), $x + 23, $y + rand() % 16, $text_color, $font, $code[1]);
imagettftext($image, $font_size, rand(-45, 45), $x + 46, $y + rand() % 16, $text_color, $font, $code[2]);
imagettftext($image, $font_size, rand(-45, 45), $x + 69, $y + rand() % 16, $text_color, $font, $code[3]);
imagettftext($image, $font_size, rand(-45, 45), $x + 92, $y + rand() % 16, $text_color, $font, $code[4]);
imagettftext($image, $font_size, rand(-45, 45), $x + 115, $y + rand() % 16, $text_color, $font, $code[5]);
header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
}
示例15: resize_image
function resize_image($pathToImages, $pathToThumbs, $thumbWidth)
{
// open the directory
$dir = opendir($pathToImages);
// loop through it, looking for any/all JPG files:
while (false !== ($fname = readdir($dir))) {
// parse path for the extension
$info = pathinfo($pathToImages . $fname);
// continue only if this is a JPEG image
if (strtolower($info['extension']) == 'jpg' && $fname != "thumb.jpg") {
// load image and get image size
$img = imagecreatefromjpeg("{$pathToImages}" . "/" . "{$fname}");
$width = imagesx($img);
$height = imagesy($img);
// calculate thumbnail size
$new_width = $thumbWidth;
$new_height = floor($height * ($thumbWidth / $width));
// create a new temporary image
$tmp_img = imagecreatetruecolor($new_width, $new_height);
// copy and resize old image into new image
imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// save thumbnail into a file
imagejpeg($tmp_img, "{$pathToThumbs}" . "/" . "{$fname}");
echo "Se redujo la imagen {$fname} <br />";
//echo "$pathToThumbs" . "/" . "$fname<br/>";
}
}
// close the directory
closedir($dir);
}