本文整理汇总了PHP中ImageJPEG函数的典型用法代码示例。如果您正苦于以下问题:PHP ImageJPEG函数的具体用法?PHP ImageJPEG怎么用?PHP ImageJPEG使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ImageJPEG函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: thumbnail
function thumbnail($PicPathIn, $PicPathOut, $PicFilenameIn, $PicFilenameOut, $neueHoehe, $Quality)
{
// Bilddaten ermitteln
$size = getimagesize("{$PicPathIn}" . "{$PicFilenameIn}");
$breite = $size[0];
$hoehe = $size[1];
$neueBreite = intval($breite * $neueHoehe / $hoehe);
if ($size[2] == 1) {
// GIF
$altesBild = ImageCreateFromGIF("{$PicPathIn}" . "{$PicFilenameIn}");
$neuesBild = imageCreateTrueColor($neueBreite, $neueHoehe);
imageCopyResized($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
imageJPEG($neuesBild, "{$PicPathOut}" . "{$PicFilenameOut}", $Quality);
}
if ($size[2] == 2) {
// JPG
$altesBild = ImageCreateFromJPEG("{$PicPathIn}" . "{$PicFilenameIn}");
$neuesBild = imageCreateTrueColor($neueBreite, $neueHoehe);
imageCopyResized($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
ImageJPEG($neuesBild, "{$PicPathOut}" . "{$PicFilenameOut}", $Quality);
}
if ($size[2] == 3) {
// PNG
$altesBild = ImageCreateFromPNG("{$PicPathIn}" . "{$PicFilenameIn}");
$neuesBild = imageCreateTrueColor($neueBreite, $neueHoehe);
imageCopyResized($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
ImageJPEG($neuesBild, "{$PicPathOut}" . "{$PicFilenameOut}", $Quality);
}
}
示例2: marcadeagua
function marcadeagua($img_original, $img_marcadeagua, $img_nueva, $calidad)
{
// obtener datos de la fotografia
$info_original = getimagesize($img_original);
$anchura_original = $info_original[0];
$altura_original = $info_original[1];
// obtener datos de la "marca de agua"
$info_marcadeagua = getimagesize($img_marcadeagua);
$anchura_marcadeagua = $info_marcadeagua[0];
$altura_marcadeagua = $info_marcadeagua[1];
// calcular la posición donde debe copiarse la "marca de agua" en la fotografia
/*
// Posicion: Centrado
$horizmargen = ($anchura_original - $anchura_marcadeagua)/2;
$vertmargen = ($altura_original - $altura_marcadeagua)/2;
*/
// Posicion: abajo a la izquierda
$horizmargen = 10;
$vertmargen = $altura_original - $altura_marcadeagua - 10;
// crear imagen desde el original
$original = ImageCreateFromJPEG($img_original);
ImageAlphaBlending($original, true);
// crear nueva imagen desde la marca de agua
$marcadeagua = ImageCreateFromPNG($img_marcadeagua);
// copiar la "marca de agua" en la fotografia
ImageCopy($original, $marcadeagua, $horizmargen, $vertmargen, 0, 0, $anchura_marcadeagua, $altura_marcadeagua);
// guardar la nueva imagen
ImageJPEG($original, $img_nueva, $calidad);
// cerrar las imágenes
ImageDestroy($original);
ImageDestroy($marcadeagua);
}
示例3: Resampling
function Resampling($tmp_name, $directorio, $name)
{
// Indico el destino del directorio de la imagen
$imagen_origen = ImageCreateFromJPEG($tmp_name);
// Calculo el tamaño de la imagen original
$tam_ancho = imagesx($imagen_origen);
$tam_alto = imagesy($imagen_origen);
//Calculo la medida que va a tener
if ($tam_ancho >= $tam_alto) {
$ancho = 38;
$alto = 38 * $tam_alto / $tam_ancho;
} else {
$ancho = 38 * $tam_ancho / $tam_alto;
$alto = 38;
}
//Creo una imagen
$imagen_destino = ImageCreateTrueColor($ancho, $alto);
//Resize
imagecopyresized($imagen_destino, $imagen_origen, 0, 0, 0, 0, $ancho, $alto, $tam_ancho, $tam_alto);
$nombre_destino = $directorio . $name;
//Genero Copia Destino
ImageJPEG($imagen_destino, $nombre_destino, 100);
//Borro imagen virtual
ImageDestroy($imagen_destino);
}
示例4: resize
function resize($src,$dst,$dstw,$dsth,$scala,$percorsosave) {
$src = $percorsosave.$src;
$dst = $percorsosave.$dst;
list($width, $height, $type, $attr) = getimagesize($src);
switch($type){
case 1:$im = imagecreatefromgif($src);break;
case 2:$im = imagecreatefromjpeg($src);break;
case 3:$im = imagecreatefrompng($src);break;
case 8:$im = imagecreatefromwbmp($src);break;
default:break;
}
If ($dstw == "0" && $dsth == "0") {
$dstw = $width;
$dsth = $height;
}
switch($scala){
//scala in base alla lunghezza
case 1:
$dsth=($height*$dstw)/$width;
break;
//scala in base all'altezza
case 2:
$dstw=($width*$dsth)/$height;
break;
default:break;
};
$tim = imagecreatetruecolor($dstw,$dsth);
imagesavealpha($tim,true);
imagealphablending($tim,false);
imagecopyresampled($tim,$im,0,0,0,0,$dstw,$dsth,$width,$height);
ImageJPEG($tim,$dst,90);
imagedestroy($tim);
}
示例5: saveImgToFile
/**
* Функция сохраняет изображение из дескриптора в файл, в соответствии с типом изображения
* Тип изображения берется из свойств класса
*
* @param (resource) $resImage - дескриптор (идентификатор) изображения
* @param (string) $newImg - имя файла, в который сохранить изображение (формат: путь/имя_файла)
*
* @return bool
*/
static function saveImgToFile($resImage, $newImg)
{
// определяем тип изображени и сохраняем его в файл
switch (self::$arrImgSubj['type']) {
case '1':
if (@ImageGIF($resImage, $newImg)) {
return true;
} else {
self::setError(ERROR_FILE_NOT_SAVED);
return false;
}
break;
case '2':
if (@ImageJPEG($resImage, $newImg, 80)) {
return true;
} else {
self::setError(ERROR_FILE_NOT_SAVED);
return false;
}
break;
case '3':
if (@ImagePNG($resImage, $newImg)) {
return true;
} else {
self::setError(ERROR_FILE_NOT_SAVED);
return false;
}
break;
}
self::setError(ERROR_FILE_NOT_SAVED);
return false;
}
示例6: SaveImage
function SaveImage($im, $filename)
{
$res = null;
// ImageGIF is not included into some GD2 releases, so it might not work
// output png if gifs are not supported
if ($this->image_type == 1 && !function_exists('imagegif')) {
$this->image_type = 3;
}
switch ($this->image_type) {
case 1:
if ($this->save_to_file) {
header("Content-type: image/gif");
$res = ImageGIF($im, $filename);
$res = ImageGIF($im, NULL);
} else {
header("Content-type: image/gif");
$res = ImageGIF($im, $filename);
$res = ImageGIF($im, NULL);
}
break;
case 2:
if ($this->save_to_file) {
header("Content-type: image/jpeg");
$res = ImageJPEG($im, $filename, $this->quality);
$res = ImageJPEG($im, NULL, $this->quality);
} else {
header("Content-type: image/jpeg");
$res = ImageJPEG($im, $filename, $this->quality);
$res = ImageJPEG($im, NULL, $this->quality);
}
break;
case 3:
if (PHP_VERSION >= '5.1.2') {
// Convert to PNG quality.
// PNG quality: 0 (best quality, bigger file) to 9 (worst quality, smaller file)
$quality = 9 - min(round($this->quality / 10), 9);
if ($this->save_to_file) {
header("Content-type: image/png");
$res = ImagePNG($im, $filename, $quality);
$res = ImagePNG($im, NULL, $quality);
} else {
header("Content-type: image/png");
$res = ImagePNG($im, $filename, $quality);
$res = ImagePNG($im, NULL, $quality);
}
} else {
if ($this->save_to_file) {
header("Content-type: image/png");
$res = ImagePNG($im, $filename);
$res = ImagePNG($im);
} else {
header("Content-type: image/png");
$res = ImagePNG($im, $filename);
$res = ImagePNG($im);
}
}
break;
}
return $res;
}
示例7: update_picture
public function update_picture()
{
if (trim($_FILES["myfile"]["tmp_name"]) != "") {
$images = $_FILES["myfile"]["tmp_name"];
$new_images = "thumb_" . $this->session->userdata('std_cardid') . '_' . $_FILES["myfile"]["name"];
copy($_FILES["myfile"]["tmp_name"], "assets/uploads/photo/" . $_FILES["myfile"]["name"]);
$width = 150;
//*** Fix Width & Heigh (Autu caculate) ***//
$size = GetimageSize($images);
$height = round($width * $size[1] / $size[0]);
$images_orig = ImageCreateFromJPEG($images);
$photoX = ImagesX($images_orig);
$photoY = ImagesY($images_orig);
$images_fin = ImageCreateTrueColor($width, $height);
ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY);
ImageJPEG($images_fin, "assets/uploads/photo/" . $new_images);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
}
$fileName = $_FILES["myfile"]["name"];
$ret[] = $fileName;
$data_picture = array('std_picture' => $new_images);
$this->Students_model->update_student_picture($this->session->userdata('std_cardid'), $data_picture);
//echo base_url()."assets/uploads/photo/".$new_images;
redirect('/front_profiles/student_edit', 'refresh');
//ChromePhp::log($ret);
//exit;
}
示例8: fixOrientation
public function fixOrientation()
{
if (exif_imagetype($this->image) == 2) {
$exif = exif_read_data($this->image);
if (array_key_exists('Orientation', $exif)) {
$orientation = $exif['Orientation'];
$images_orig = ImageCreateFromJPEG($this->image);
$rotate = "";
switch ($orientation) {
case 3:
$rotate = imagerotate($images_orig, 180, 0);
break;
case 6:
$rotate = imagerotate($images_orig, -90, 0);
break;
case 8:
$rotate = imagerotate($images_orig, 90, 0);
break;
}
if ($rotate != "") {
ImageJPEG($rotate, $this->image);
ImageDestroy($rotate);
}
ImageDestroy($images_orig);
}
}
}
示例9: generateImage
function generateImage($token)
{
$iFont = 5;
// Font ID
$iSpacing = 2;
// Spacing between characters
$iDisplacement = 5;
// Vertical chracter displacement
// Establish font metric and image size
$iCharWidth = ImageFontWidth($iFont);
$iCharHeight = ImageFontHeight($iFont);
$iWidth = strlen($token) * ($iCharWidth + $iSpacing);
$iHeight = $iCharHeight + 2 * $iDisplacement;
// Create the image
$pic = ImageCreate($iWidth, $iHeight);
// Allocate a background and foreground colour
$col = array('white' => ImageColorAllocate($pic, 255, 255, 255), 'blue' => ImageColorAllocate($pic, 45, 45, 100), 'green' => ImageColorAllocate($pic, 45, 100, 45), 'red' => ImageColorAllocate($pic, 100, 45, 45), 'purple' => ImageColorAllocate($pic, 100, 45, 100), 'grey' => ImageColorAllocate($pic, 225, 225, 225), 'grey2' => ImageColorAllocate($pic, 200, 200, 200));
for ($x = 0; $x < $iWidth; $x += 2) {
for ($y = 0; $y < $iHeight; $y += 2) {
ImageSetPixel($pic, $x, $y, $col['grey']);
}
}
$iX = 1;
for ($i = 0; $i < strlen($token); $i++) {
ImageChar($pic, $iFont - 1, $iX, $iDisplacement - rand(-$iDisplacement, $iDisplacement), $token[$i], $col['grey2']);
$iX += $iCharWidth + $iSpacing;
}
$iX = 2;
$c = array('blue', 'green', 'red', 'purple');
for ($i = 0; $i < strlen($token); $i++) {
$colour = $c[rand(0, count($c) - 1)];
ImageChar($pic, $iFont, $iX, $iDisplacement - rand(-$iDisplacement, $iDisplacement), $token[$i], $col[$colour]);
$iX += $iCharWidth + $iSpacing;
}
for ($x = 1; $x < $iWidth; $x += 4) {
for ($y = 1; $y < $iHeight; $y += 4) {
ImageSetPixel($pic, $x, $y, $col['white']);
}
}
// Draw some lines
for ($i = 0; $i < 4; $i++) {
ImageLine($pic, rand(0, $iWidth / 2), rand(0, $iHeight / 2), rand($iWidth / 2, $iWidth), rand($iHeight / 2, $iHeight), $col['white']);
}
ob_start();
if (function_exists('imagejpeg')) {
ImageJPEG($pic);
} elseif (function_exists('imagepng')) {
ImagePNG($pic);
} else {
ob_end_clean();
return false;
}
$data = ob_get_contents();
ob_end_clean();
ImageDestroy($pic);
return $data;
}
示例10: twMachThumbnail
function twMachThumbnail($serverPfad, $datei, $breiteThumb, $prefix)
{
// Bild-Datei (mit Pfad)
$bildDatei = $serverPfad . $datei;
// wenn dieses Bild nich gefunden wurde: Abbruch
if (!file_exists($bildDatei)) {
return false;
}
// wenn dieses Bild schon ein Thumbnail ist: Abbruch
if (substr($datei, 0, strlen($prefix)) == $prefix) {
//echo $datei. "<br />";
//echo strlen($prefix). "<br />";
//echo $prefix. "<br />";
//echo substr($datei, strlen($prefix)). "<br />";
//echo "-----<br />";
return false;
}
// Bilddaten zu dieser Bild-Datei
$bilddaten = getimagesize($bildDatei);
$imgOrigBreite = $bilddaten[0];
$imgOrigHoehe = $bilddaten[1];
$imgOrigTyp = $bilddaten[2];
// (1=GIF, 2=JPG, 3=PNG, 4=SWF)
if ($imgOrigBreite < $breiteThumb) {
$breiteThumb = $imgOrigBreite;
}
$Skalierungsfaktor = $imgOrigBreite / $breiteThumb;
$thumbHoehe = intval($imgOrigHoehe / $Skalierungsfaktor);
// wenn es ein gif-Bild ist
if ($imgOrigTyp == 1) {
$Originalgrafik = ImageCreateFromGIF($bildDatei);
$Thumbnailgrafik = ImageCreateTrueColor($breiteThumb, $thumbHoehe);
ImageCopyResized($Thumbnailgrafik, $Originalgrafik, 0, 0, 0, 0, $breiteThumb, $thumbHoehe, $imgOrigBreite, $imgOrigHoehe);
ImageGIF($Thumbnailgrafik, $serverPfad . $prefix . $datei, 100);
} elseif ($imgOrigTyp == 2) {
$Originalgrafik = ImageCreateFromJPEG($bildDatei);
$Thumbnailgrafik = ImageCreateTrueColor($breiteThumb, $thumbHoehe);
ImageCopyResized($Thumbnailgrafik, $Originalgrafik, 0, 0, 0, 0, $breiteThumb, $thumbHoehe, $imgOrigBreite, $imgOrigHoehe);
///ImageJPEG($Thumbnailgrafik, $pfad."thumb_".$bild);
ImageJPEG($Thumbnailgrafik, $serverPfad . $prefix . $datei, 100);
} elseif ($imgOrigTyp == 3) {
$Originalgrafik = ImageCreateFromPNG($bildDatei);
$Thumbnailgrafik = ImageCreateTrueColor($breiteThumb, $thumbHoehe);
ImageCopyResized($Thumbnailgrafik, $Originalgrafik, 0, 0, 0, 0, $breiteThumb, $thumbHoehe, $imgOrigBreite, $imgOrigHoehe);
ImagePNG($Thumbnailgrafik, $serverPfad . $prefix . $datei, 100);
} else {
return false;
}
// Speicher leeren
if ($Originalgrafik) {
imagedestroy($Originalgrafik);
}
if ($Thumbnailgrafik) {
imagedestroy($Thumbnailgrafik);
}
}
示例11: getImage
/**
* Get image
* @params string
**/
function getImage($val)
{
$document =& JFactory::getDocument();
$document->setMimeEncoding('image/jpg');
$im = @imagecreatetruecolor(100, 40) or die('Cannot create image');
$text_color = imagecolorallocate($im, 233, 14, 91);
Imagestring($im, 1, 5, 5, $val, $text_color);
@ImageJPEG($img, null, 100);
Imagedestroy($im);
}
示例12: Resize
function Resize($maxwidth = 10000, $maxheight, $imagename, $filetype, $how = 'keep_aspect')
{
$target_temp_file = tempnam("jinn/temp", "gdlib_");
unlink($target_temp_file);
$target_temp_file .= '.' . $filetype;
if (!$maxheight) {
$maxheight = 10000;
}
if (!$maxwidth) {
$maxwidth = 10000;
}
$qual = 100;
$filename = $imagename;
$ext = $filetype;
list($curwidth, $curheight) = getimagesize($filename);
$factor = min($maxwidth / $curwidth, $maxheight / $curheight);
$sx = 0;
$sy = 0;
$sw = $curwidth;
$sh = $curheight;
$dx = 0;
$dy = 0;
$dw = $curwidth * $factor;
$dh = $curheight * $factor;
if ($ext == "JPEG") {
$src = ImageCreateFromJPEG($filename);
}
if ($ext == "GIF") {
$src = ImageCreateFromGIF($filename);
}
if ($ext == "PNG") {
$src = ImageCreateFromPNG($filename);
}
if (function_exists('ImageCreateTrueColor')) {
$dst = ImageCreateTrueColor($dw, $dh);
} else {
$dst = ImageCreate($dw, $dh);
}
if (function_exists('ImageCopyResampled')) {
imageCopyResampled($dst, $src, $dx, $dy, $sx, $sy, $dw, $dh, $sw, $sh);
} else {
imageCopyResized($dst, $src, $dx, $dy, $sx, $sy, $dw, $dh, $sw, $sh);
}
if ($ext == "JPEG") {
ImageJPEG($dst, $target_temp_file, $qual);
}
if ($ext == "PNG") {
ImagePNG($dst, $target_temp_file, $qual);
}
if ($ext == "GIF") {
ImagePNG($dst, $target_temp_file, $qual);
}
ImageDestroy($dst);
return $target_temp_file;
}
示例13: show_gd_img
function show_gd_img($content = "")
{
$content = ' ' . preg_replace("/(\\w)/", "\\1 ", $content) . ' ';
$gd_version = 2;
@header("Content-Type: image/jpeg");
$tmp_x = 140;
$tmp_y = 20;
$image_x = 210;
$image_y = 65;
$circles = 3;
if ($gd_version == 1) {
$tmp = imagecreate($tmp_x, $tmp_y);
$im = imagecreate($image_x, $image_y);
} else {
$tmp = imagecreatetruecolor($tmp_x, $tmp_y);
$im = imagecreatetruecolor($image_x, $image_y);
}
$white = ImageColorAllocate($tmp, 255, 255, 255);
$black = ImageColorAllocate($tmp, 0, 0, 0);
$grey = ImageColorAllocate($tmp, 210, 210, 210);
imagefill($tmp, 0, 0, $white);
for ($i = 1; $i <= $circles; $i++) {
$values = array(0 => rand(0, $tmp_x - 10), 1 => rand(0, $tmp_y - 3), 2 => rand(0, $tmp_x - 10), 3 => rand(0, $tmp_y - 3), 4 => rand(0, $tmp_x - 10), 5 => rand(0, $tmp_y - 3), 6 => rand(0, $tmp_x - 10), 7 => rand(0, $tmp_y - 3), 8 => rand(0, $tmp_x - 10), 9 => rand(0, $tmp_y - 3), 10 => rand(0, $tmp_x - 10), 11 => rand(0, $tmp_y - 3));
$randomcolor = imagecolorallocate($tmp, rand(100, 255), rand(100, 255), rand(100, 255));
imagefilledpolygon($tmp, $values, 6, $randomcolor);
}
imagestring($tmp, 5, 0, 2, $content, $black);
//-----------------------------------------
// Distort by resizing
//-----------------------------------------
imagecopyresized($im, $tmp, 0, 0, 0, 0, $image_x, $image_y, $tmp_x, $tmp_y);
imagedestroy($tmp);
$white = ImageColorAllocate($im, 255, 255, 255);
$black = ImageColorAllocate($im, 0, 0, 0);
$grey = ImageColorAllocate($im, 100, 100, 100);
$random_pixels = $image_x * $image_y / 10;
for ($i = 0; $i < $random_pixels; $i++) {
ImageSetPixel($im, rand(0, $image_x), rand(0, $image_y), $black);
}
$no_x_lines = ($image_x - 1) / 5;
for ($i = 0; $i <= $no_x_lines; $i++) {
// X lines
ImageLine($im, $i * $no_x_lines, 0, $i * $no_x_lines, $image_y, $grey);
// Diag lines
ImageLine($im, $i * $no_x_lines, 0, $i * $no_x_lines + $no_x_lines, $image_y, $grey);
}
$no_y_lines = ($image_y - 1) / 5;
for ($i = 0; $i <= $no_y_lines; $i++) {
ImageLine($im, 0, $i * $no_y_lines, $image_x, $i * $no_y_lines, $grey);
}
ImageJPEG($im);
ImageDestroy($im);
exit;
}
示例14: BannerError
function BannerError($Message)
{
HTTP::sendHeader('Content-type', 'image/jpg');
$im = ImageCreate(450, 80);
$background_color = ImageColorAllocate($im, 255, 255, 255);
$text_color = ImageColorAllocate($im, 233, 14, 91);
ImageString($im, 3, 5, 5, $Message, $text_color);
ImageJPEG($im);
imagedestroy($im);
exit;
}
示例15: createPhoto
function createPhoto ($old) {
global $fold,$pref;
$q = 100;
$img = ImageCreateFromJPEG($fold.$old);
$font = "tahoma.ttf";
$dom = "Hello World!";
$color = imagecolorallocate ($img, 0, 0, 0);
imagettftext ($img, 50, 0, 55, 625, $color, $font, $dom);
ImageJPEG($img, $fold.$pref.$old, $q);
ImageDestroy($img);
}