本文整理汇总了PHP中ImageCreateTrueColor函数的典型用法代码示例。如果您正苦于以下问题:PHP ImageCreateTrueColor函数的具体用法?PHP ImageCreateTrueColor怎么用?PHP ImageCreateTrueColor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ImageCreateTrueColor函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: newGalleryImage
static function newGalleryImage($image)
{
# Grab filename and image type from upload
$file_ext = self::$imageTypes[$image['type']];
$filename = $image['name'];
# Upload of image
copy($image['tmp_name'], "gallery_images/" . $filename);
# Grabs file suffix for variable function calls
$function_suffix = strtoupper($file_ext);
# Variable read/write functions for image creation
$function_to_read = 'ImageCreateFrom' . $function_suffix;
$function_to_write = 'Image' . $function_suffix;
# Determine the file size and create a proportionally sized thumbnail
$size = GetImageSize("gallery_images/" . $filename);
if ($size[0] > $size[1]) {
$thumbnail_width = 200;
$thumbnail_height = (int) (200 * $size[1] / $size[0]);
} else {
$thumbnail_width = (int) (200 * $size[0] / $size[1]);
$thumbnail_height = 200;
}
$source_handle = $function_to_read("gallery_images/" . $filename);
if ($source_handle) {
$destination_handle = ImageCreateTrueColor($thumbnail_width, $thumbnail_height);
ImageCopyResampled($destination_handle, $source_handle, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $size[0], $size[1]);
}
$function_to_write($destination_handle, "gallery_images/tb/" . $filename);
}
示例2: 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}");
}
示例3: recorta_imagem_perfil_usuario
function recorta_imagem_perfil_usuario()
{
// imagem normal
$targ_w[0] = TAMANHO_IMG_PERFIL_RECORTAR_LARGURA;
$targ_h[0] = TAMANHO_IMG_PERFIL_RECORTAR_ALTURA;
// imagem miniatura
$targ_w[1] = TAMANHO_IMG_PERFIL_RECORTAR_LARGURA_MIN;
$targ_h[1] = TAMANHO_IMG_PERFIL_RECORTAR_ALTURA_MIN;
// qualidade
$jpeg_quality = 100;
// criando nova imagem
$src[0] = remove_html($_REQUEST['imagem_perfil']);
$img_r[0] = imagecreatefromjpeg($src[0]);
$dst_r[0] = ImageCreateTrueColor($targ_w[0], $targ_h[0]);
imagecopyresampled($dst_r[0], $img_r[0], 0, 0, $_POST['x'], $_POST['y'], $targ_w[0], $targ_h[0], $_POST['w'], $_POST['h']);
// criando nova imagem
$src[1] = remove_html($_REQUEST['imagem_perfil']);
$img_r[1] = imagecreatefromjpeg($src[1]);
$dst_r[1] = ImageCreateTrueColor($targ_w[1], $targ_h[1]);
imagecopyresampled($dst_r[1], $img_r[1], 0, 0, $_POST['x'], $_POST['y'], $targ_w[1], $targ_h[1], $_POST['w'], $_POST['h']);
// dados da imagem
$dados_imagem = retorne_imagem_perfil_usuario_root();
// dados de retorno
$imagem_perfil = $dados_imagem['imagem_perfil'];
$imagem_perfil_miniatura = $dados_imagem['imagem_perfil_miniatura'];
// grava a nova imagem
imagejpeg($dst_r[0], $imagem_perfil);
imagejpeg($dst_r[1], $imagem_perfil_miniatura);
// chama a pagina inicial
chama_pagina_inicial();
}
示例4: crop
/**
* crop image
*/
public static function crop($filename, $x, $y, $w, $h, $targ_w, $targ_h)
{
$extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
switch ($extension) {
case 'gif':
$img_r = imagecreatefromgif($filename);
$dst_r = ImageCreateTrueColor($targ_w, $targ_h);
imagecopyresampled($dst_r, $img_r, 0, 0, $x, $y, $targ_w, $targ_h, $w, $h);
imagegif($dst_r, $filename);
break;
case 'jpg':
case 'jpeg':
$img_r = imagecreatefromjpeg($filename);
$dst_r = ImageCreateTrueColor($targ_w, $targ_h);
imagecopyresampled($dst_r, $img_r, 0, 0, $x, $y, $targ_w, $targ_h, $w, $h);
imagejpeg($dst_r, $filename, 75);
break;
case 'png':
$img_r = imagecreatefrompng($filename);
$dst_r = ImageCreateTrueColor($targ_w, $targ_h);
imagealphablending($dst_r, false);
imagesavealpha($dst_r, true);
imagecopyresampled($dst_r, $img_r, 0, 0, $x, $y, $targ_w, $targ_h, $w, $h);
imagepng($dst_r, $filename, 9);
break;
default:
return false;
}
return true;
}
示例5: TransFormPicture
function TransFormPicture($inputfname, $outputfname, $transform, $backgroundcolor)
{
$img_in = ImageCreateFromPNG($inputfname);
$sizex = imagesx($img_in);
$sizey = imagesy($img_in);
$img_out = @ImageCreateTrueColor($sizex, $sizey) or die("Cannot create image handle.");
imagefill($img_out, 0, 0, hexdec($backgroundcolor));
ImageCopy($img_out, $img_in, 0, 0, 0, 0, $sizex, $sizey);
for ($x = 0; $x < $sizex; $x++) {
for ($y = 0; $y < $sizey; $y++) {
$color = imagecolorat($img_in, $x, $y);
$allcolors[dechex($color)]++;
$blue = 0xff & $color;
$green = (0xff00 & $color) >> 8;
$red = (0xff0000 & $color) >> 16;
foreach ($transform as $line) {
list($from, $to) = split("\t", $line);
list($fr, $fg, $fb) = sscanf($from, '%2x%2x%2x');
if ($blue == $fb and $red == $fr and $green == $fg) {
imagesetpixel($img_out, $x, $y, hexdec($to));
}
}
}
}
ImagePNG($img_out, "out/{$outputfname}");
imagedestroy($img_in);
imagedestroy($img_out);
print_r($allcolors);
}
示例6: execute
function execute()
{
if (!$this->image->isImage()) {
return false;
}
$gdimage =& $this->image->getImage();
$w = $this->image->getWidth();
$h = $this->image->getHeight();
$src_x = ceil($w);
$src_y = ceil($h);
$dst_x = $src_x;
$dst_y = $src_y;
$dst_im = ImageCreateTrueColor($dst_x, $dst_y);
ImageCopyResampled($dst_im, $gdimage, 0, 0, 0, 0, $dst_x, $dst_y, $src_x, $src_y);
for ($c = 0; $c < 256; $c++) {
$palette[$c] = imagecolorallocate($dst_im, $c, $c, $c);
}
for ($y = 0; $y < $src_y; $y++) {
for ($x = 0; $x < $src_x; $x++) {
$rgb = imagecolorat($dst_im, $x, $y);
$r = $rgb >> 16 & 0xff;
$g = $rgb >> 8 & 0xff;
$b = $rgb & 0xff;
$gs = $r * 0.299 + $g * 0.587 + $b * 0.114;
imagesetpixel($dst_im, $x, $y, $palette[$gs]);
}
}
$gdimage = $dst_im;
}
示例7: 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);
}
示例8: execute
public function execute()
{
$this->media->asImage();
$gdimage = $this->media->getImage();
$w = $this->media->getWidth();
$h = $this->media->getHeight();
$src_x = ceil($w);
$src_y = ceil($h);
$dst_x = $src_x;
$dst_y = $src_y;
$dst_im = ImageCreateTrueColor($dst_x, $dst_y);
ImageCopyResampled($dst_im, $gdimage, 0, 0, 0, 0, $dst_x, $dst_y, $src_x, $src_y);
for ($c = 0; $c < 256; ++$c) {
$palette[$c] = imagecolorallocate($dst_im, $c, $c, $c);
}
for ($y = 0; $y < $src_y; ++$y) {
for ($x = 0; $x < $src_x; ++$x) {
$rgb = imagecolorat($dst_im, $x, $y);
$r = $rgb >> 16 & 0xff;
$g = $rgb >> 8 & 0xff;
$b = $rgb & 0xff;
$gs = $r * 0.299 + $g * 0.587 + $b * 0.114;
imagesetpixel($dst_im, $x, $y, $palette[$gs]);
}
}
$this->media->setImage($dst_im);
}
示例9: resize
public function resize($width, $height)
{
$type = exif_imagetype($this->image);
if ($type == 2) {
$images_orig = ImageCreateFromJPEG($this->image);
} elseif ($type == 3) {
$images_orig = ImageCreateFromPNG($this->image);
} elseif ($type == 1) {
$images_orig = ImageCreateFromGIF($this->image);
} else {
return false;
}
$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);
if ($type == 2) {
ImageJPEG($images_fin, $this->image);
} elseif ($type == 3) {
ImagePNG($images_fin, $this->image);
} elseif ($type == 1) {
ImageGIF($images_fin, $this->image);
}
ImageDestroy($images_orig);
ImageDestroy($images_fin);
return true;
}
示例10: 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;
}
示例11: createthumb
function createthumb($name, $filename, $new_w, $new_h)
{
$system = explode(".", $name);
if (preg_match("/jpg|jpeg/", $system[1])) {
$src_img = imagecreatefromjpeg($name);
}
if (preg_match("/png/", $system[1])) {
$src_img = imagecreatefrompng($name);
}
$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;
}
$dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
if (preg_match("/png/", $system[1])) {
imagepng($dst_img, $filename);
} else {
imagejpeg($dst_img, $filename);
}
imagedestroy($dst_img);
imagedestroy($src_img);
}
示例12: 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;
}
}
示例13: ResizeImage
function ResizeImage($image_from, $image_to, $fitwidth = 200, $fitheight = 270, $quality = 75)
{
$os = $originalsize = getimagesize($image_from);
if ($originalsize[2] != 2 && $originalsize[2] != 3 && $originalsize[2] != 6 && ($originalsize[2] < 9 or $originalsize[2] > 12)) {
return false;
}
if ($originalsize[0] > $fitwidth or $originalsize[1] > $fitheight) {
$h = getimagesize($image_from);
if ($h[0] / $fitwidth > $h[1] / $fitheight) {
$fitheight = $h[1] * $fitwidth / $h[0];
} else {
$fitwidth = $h[0] * $fitheight / $h[1];
}
if ($os[2] == 2 or $os[2] >= 9 && $os[2] <= 12) {
$i = ImageCreateFromJPEG($image_from);
}
$o = ImageCreateTrueColor($fitwidth, $fitheight);
imagecopyresampled($o, $i, 0, 0, 0, 0, $fitwidth, $fitheight, $h[0], $h[1]);
imagejpeg($o, $image_to, $quality);
chmod($image_to, 0777);
imagedestroy($o);
imagedestroy($i);
return 2;
}
if ($originalsize[0] <= $fitwidth && $originalsize[1] <= $fitheight) {
$i = ImageCreateFromJPEG($image_from);
imagejpeg($i, $image_to, $quality);
chmod($image_to, 0777);
return 1;
}
}
示例14: resizeImg
function resizeImg($origPath, $mW, $mH)
{
// Read the size
$rst['size'] = GetImageSize($origPath);
$w = $rst['size'][0];
$h = $rst['size'][1];
// Proportionally resize the image to the max sizes specified above
$xRatio = $mW / $w;
$yRatio = $mH / $h;
if ($w <= $mW && $h <= $mH) {
$tnW = $w;
$tnH = $h;
} elseif ($xRatio * $h < $mH) {
$tnH = ceil($xRatio * $h);
$tnW = $mW;
} else {
$tnW = ceil($yRatio * $w);
$tnH = $mH;
}
// Create the new image!
if ($rst['size']['mime'] == 'image/jpg' || $rst['size']['mime'] == 'image/jpeg') {
$rst['src'] = imagecreatefromjpeg($origPath);
$rst['dst'] = ImageCreateTrueColor($tnW, $tnH);
$rst['resize'] = ImageCopyResized($rst['dst'], $rst['src'], 0, 0, 0, 0, $tnW, $tnH, $w, $h);
$rst['imgMod'] = imagejpeg($rst['dst'], $origPath, 100);
} else {
$rst['note'] = 'Error with file type!';
return false;
}
return $rst;
}
示例15: cropBilde
private function cropBilde($sti, $filnavn, $nyttFilnavn, $cropBredde, $cropHoyde)
{
$gammeltBilde = $sti . $filnavn;
$bi = @ImageCreateFromJPEG($gammeltBilde) or $bi = @ImageCreateFromPNG($gammeltBilde) or $bi = @ImageCreateFromGIF($gammeltBilde) or $bi = false;
if ($bi) {
$naStorrelse = @getimagesize($gammeltBilde);
$bredde = $naStorrelse[0];
$hoyde = $naStorrelse[1];
$nyBreddeNy = $bredde / $cropBredde;
$nyHoydeNy = $hoyde / $cropHoyde;
$halvertHoyde = $cropHoyde / 2;
$halvertBredde = $cropBredde / 2;
$thumb = @ImageCreateTrueColor($cropBredde, $cropHoyde);
if ($bredde > $hoyde) {
$tilpassetBredde = $bredde / $nyHoydeNy;
$halvBredde = $tilpassetBredde / 2;
$intBredde = $halvBredde - $halvertBredde;
@ImageCopyResampled($thumb, $bi, -$intBredde, 0, 0, 0, $tilpassetBredde, $cropHoyde, $bredde, $hoyde);
} elseif ($bredde < $hoyde || $bredde == $hoyde) {
$tilPassetHoyde = $hoyde / $nyBreddeNy;
$halvHoyde = $tilPassetHoyde / 2;
$intHoyde = $halvHoyde - $halvertHoyde;
@ImageCopyResampled($thumb, $bi, 0, -$intHoyde, 0, 0, $cropBredde, $tilPassetHoyde, $bredde, $hoyde);
} else {
@ImageCopyResampled($thumb, $bi, 0, 0, 0, 0, $cropBredde, $cropHoyde, $bredde, $hoyde);
}
@imagejpeg($thumb, $sti . $nyttFilnavn, 50);
return $nyttFilnavn;
} else {
return -1;
}
}