本文整理汇总了PHP中ImageCreate函数的典型用法代码示例。如果您正苦于以下问题:PHP ImageCreate函数的具体用法?PHP ImageCreate怎么用?PHP ImageCreate使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ImageCreate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: MyImageBlur
function MyImageBlur($im, $pct) {
// w00t. my very own blur function
// in GD2, there's a gaussian blur function. smarmy bastards. ;-)
$width = imagesx($im);
$height = imagesy($im);
$temp_im = ImageCreate($width, $height);
$bg = ImageColorAllocate($temp_im, 255, 255, 255);
// preserves transparency if in orig image
ImageColorTransparent($temp_im, $bg);
// fill bg
ImageFill($temp_im, 0, 0, $bg);
$distance = 1;
// emboss:
ImageCopyMerge($temp_im, $im, 0, 0, $distance, $distance, $width, $height, $pct);
ImageCopyMerge($im, $temp_im, -$distance, -$distance, 0, 0, $width, $height, $pct);
ImageFill($temp_im, 0, 0, $bg);
ImageCopyMerge($temp_im, $im, 0, $distance, $distance, 0, $width, $height, $pct);
ImageCopyMerge($im, $temp_im, $distance, 0, 0, $distance, $width, $height, $pct);
// blur:
ImageCopyMerge($temp_im, $im, 0, $distance, 0, 0, $width, $height, $pct);
ImageCopyMerge($im, $temp_im, $distance, 0, 0, 0, $width, $height, $pct);
ImageCopyMerge($temp_im, $im, 0, 0, 0, $distance, $width, $height, $pct);
ImageCopyMerge($im, $temp_im, 0, 0, $distance, 0, $width, $height, $pct);
// remove temp image
ImageDestroy($temp_im);
return $im;
}
示例2: init_resultat_election
function init_resultat_election()
{
global $image, $blanc, $noir, $gris, $gris2;
header("Content-type: image/png");
$annee = $_REQUEST[annee];
$genre = $_REQUEST[genre];
$type = $_REQUEST[type];
$lesMiss = selectDbMiss($annee, $genre, $type, "", true);
usort($lesMiss, "callback_sort_nb_votes");
$nb = count($lesMiss);
$hauteur = TAILLE_BARRE * $nb;
$largeur = TAILLE_HAUTEUR;
$image = ImageCreate($hauteur, $largeur);
// On passe en blanc le fond de l'image
$blanc = imagecolorallocate($image, 255, 255, 255);
$noir = imagecolorallocate($image, 0, 0, 0);
$gris = ImageColorAllocate($image, 190, 190, 190);
$gris2 = ImageColorAllocate($image, 140, 140, 140);
imagefilledrectangle($image, 0, 0, $largeur, $hauteur, $blanc);
$total_votes = nombre_votes_db($annee, $genre, $type);
dessine_nom_results_miss($lesMiss, $total_votes);
// Génération de l'image
ImagePng($image);
// Desctruction de l'image
ImageDestroy($image);
}
示例3: image
private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4, $wh = false)
{
$h = count($frame);
$w = strlen($frame[0]);
$imgW = $w + 2 * $outerFrame;
$imgH = $h + 2 * $outerFrame;
$base_image = ImageCreate($imgW, $imgH);
$col[0] = ImageColorAllocate($base_image, 255, 255, 255);
$col[1] = ImageColorAllocate($base_image, 0, 0, 0);
imagefill($base_image, 0, 0, $col[0]);
for ($y = 0; $y < $h; $y++) {
for ($x = 0; $x < $w; $x++) {
if ($frame[$y][$x] == '1') {
ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]);
}
}
}
$www = $imgW * $pixelPerPoint;
$hhh = $imgH * $pixelPerPoint;
if (is_array($wh)) {
$www = $wh[0];
$hhh = $wh[1];
}
$target_image = ImageCreate($www, $hhh);
ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $www, $hhh, $imgW, $imgH);
ImageDestroy($base_image);
return $target_image;
}
示例4: 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);
}
}
示例5: display
/**
* $IMG_WIDTH = 100; //图像宽度
$IMG_HEIGHT = 23; //图像高度
$SESSION_VDCODE = ''; //Session变量名称
* $operator = '+-'; //运算符
*/
public static function display($IMG_WIDTH = 70, $IMG_HEIGHT = 25, $SESSION_VDCODE = 'vdcode', $operator = '+')
{
$session_id = session_id();
if (empty($session_id)) {
@session_start();
}
$code = array();
$num1 = $code[] = mt_rand(1, 9);
$code[] = '+';
//{mt_rand(0,1)};
$num2 = $code[] = mt_rand(1, 9);
$codestr = implode('', $code);
//eval("\$result = ".implode('',$code).";");
$code[] = '=';
$_SESSION[$SESSION_VDCODE] = (int) $num1 + (int) $num2;
$img = ImageCreate($IMG_WIDTH, $IMG_HEIGHT);
ImageColorAllocate($img, mt_rand(230, 250), mt_rand(230, 250), mt_rand(230, 250));
$color = ImageColorAllocate($img, 0, 0, 0);
$offset = 0;
foreach ($code as $char) {
$offset += 15;
$txtcolor = ImageColorAllocate($img, mt_rand(0, 255), mt_rand(0, 150), mt_rand(0, 255));
ImageChar($img, mt_rand(3, 5), $offset, mt_rand(1, 5), $char, $txtcolor);
}
for ($i = 0; $i < 100; $i++) {
$pxcolor = ImageColorAllocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
ImageSetPixel($img, mt_rand(0, $IMG_WIDTH), mt_rand(0, $IMG_HEIGHT), $pxcolor);
}
header('Content-type: image/png');
ImagePng($img);
exit;
}
示例6: ConvertToImage
function ConvertToImage($content)
{
$imageFile = ".counter.png";
$relativePath = ".counter.png";
$noOfChars = strlen($content);
$charHeight = ImageFontHeight(5);
$charWidth = ImageFontWidth(5);
$strWidth = $charWidth * $noOfChars;
$strHeight = $charHeight;
//15 padding
$imgWidth = $strWidth + 15;
$imgHeight = $strHeight + 15;
$imgCenterX = $imgWidth / 2;
$imgCenterY = $imgHeight / 2;
$im = ImageCreate($imgWidth, $imgHeight);
$script = ImageColorAllocate($im, 0, 255, 0);
$outercolor = ImageColorAllocate($im, 99, 140, 214);
$innercolor = ImageColorAllocate($im, 0, 0, 0);
ImageFilledRectangle($im, 0, 0, $imgWidth, $imgHeight, $outercolor);
ImageFilledRectangle($im, 3, 3, $imgWidth - 4, $imgHeight - 4, $innercolor);
//draw string
$drawPosX = $imgCenterX - $strWidth / 2 + 1;
$drawPosY = $imgCenterY - $strHeight / 2;
ImageString($im, 5, $drawPosX, $drawPosY, $content, $script);
//save image and return
ImagePNG($im, $imageFile);
return $relativePath;
}
示例7: guvenlik_resmi
function guvenlik_resmi()
{
$sifre = substr(md5(rand(0, 999999999999)), -5);
if ($sifre) {
$this->session->set_userdata('koruma', $sifre);
$yukseklik = 62;
$genislik = 200;
$resim = ImageCreate($genislik, $yukseklik);
$siyah = ImageColorAllocate($resim, 0, 0, 0);
$kirmizi = ImageColorAllocate($resim, 182, 16, 99);
$beyaz = ImageColorAllocate($resim, 255, 255, 255);
ImageFill($resim, 0, 0, $beyaz);
$font = 'css/comic.ttf';
$font_boyut = 24;
$sM = 30;
$uM = 45;
//kullanımı
//resim adı, font boyutu, yazının açısı, yazının soldan margini, üstten margin, renk, font adı, şifrenin hangi digitinin yazılacağı bellirtiliyor
imagettftext($resim, $font_boyut, rand(-45, 45), $sMa = $sM, $uM, rand(0, 255), $font, $sifre[0]);
imagettftext($resim, $font_boyut, rand(-45, 45), $sM = $sMa + $sM, $uM, rand(0, 255), $font, $sifre[1]);
imagettftext($resim, $font_boyut, rand(-45, 45), $sM = $sMa + $sM, $uM, rand(0, 255), $font, $sifre[2]);
imagettftext($resim, $font_boyut, rand(-45, 45), $sM = $sMa + $sM, $uM, rand(0, 255), $font, $sifre[3]);
imagettftext($resim, $font_boyut, rand(-45, 45), $sM = $sMa + $sM, $uM, rand(0, 255), $font, $sifre[4]);
//ImageRectangle($resim, 0, 0, $genislik-1, $yukseklik-1, $kirmizi);
imageline($resim, 0, $yukseklik / 2, $genislik, $yukseklik / 2, $kirmizi);
imageline($resim, $genislik / 2, 0, $genislik / 2, $yukseklik, $kirmizi);
header("Content-Type: image/png");
ImagePng($resim);
ImageDestroy($resim);
}
exit;
}
示例8: 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);
}
示例9: GraphNormalize
function GraphNormalize($title, $options = NULL)
{
$this->options = $options;
$this->interval = $this->options['interval'] ? $this->options['interval'] : 10;
// TODO: Move these to friendly options
$this->image_size = array(600, 400);
$this->canvas_offset = array(25, 50, 25, 25);
$this->canvas_size = array($this->image_size[0] - ($this->canvas_offset[0] + $this->canvas_offset[2]), $this->image_size[1] - ($this->canvas_offset[1] + $this->canvas_offset[3]));
// Actual creation stuff
$this->graph = ImageCreate($this->image_size[0], $this->image_size[1]);
$this->color['background'] = ImageColorAllocate($this->graph, 0xff, 0xff, 0xff);
$this->color['line'] = ImageColorAllocate($this->graph, 0x60, 0x60, 0x60);
$this->color['border'] = ImageColorAllocate($this->graph, 0x0, 0x0, 0x0);
$this->color['text'] = ImageColorAllocate($this->graph, 0x0, 0x0, 0x0);
$this->color['grid'] = ImageColorAllocate($this->graph, 0xc0, 0xc0, 0xc0);
$this->color['canvas'] = ImageColorAllocate($this->graph, 0xe0, 0xe0, 0xe0);
$this->color['legendbox'] = ImageColorAllocate($this->graph, 0xd0, 0xd0, 0xf0);
$this->color['titlebox'] = ImageColorAllocate($this->graph, 0xd0, 0xf0, 0xf0);
$this->color['data'] = array(ImageColorAllocate($this->graph, 0xff, 0x0, 0x0), ImageColorAllocate($this->graph, 0x0, 0xcc, 0x0), ImageColorAllocate($this->graph, 0x0, 0x0, 0xff), ImageColorAllocate($this->graph, 0xff, 0xff, 0x0), ImageColorAllocate($this->graph, 0x0, 0xff, 0xff), ImageColorAllocate($this->graph, 0xff, 0x0, 0xff));
$this->font = 'lib/template/default/Vera.ttf';
$this->title = $title;
$this->set_count = 0;
// Define canvas, so we don't go crazy
$this->ca = array($this->canvas_offset[0], $this->canvas_offset[1], $this->canvas_size[0] - $this->canvas_offset[2] - 1, $this->canvas_size[1] - $this->canvas_offset[3] - 1);
}
示例10: image
private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4)
{
$h = count($frame);
$w = strlen($frame[0]);
$imgW = $w + 2 * $outerFrame;
$imgH = $h + 2 * $outerFrame;
$base_image = imagecreatetruecolor($imgW, $imgH);
$col[0] = ImageColorAllocate($base_image, 255, 0, 255);
$col[1] = ImageColorAllocate($base_image, 0, 0, 0);
imagecolortransparent($base_image, $col[0]);
imagealphablending($base_image, true);
imagesavealpha($base_image, true);
// imagefill($base_image, 0, 0, $col[0]);
imagefill($base_image, 0, 0, 0x7fff0000);
for ($y = 0; $y < $h; $y++) {
for ($x = 0; $x < $w; $x++) {
if ($frame[$y][$x] == '1') {
ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]);
}
}
}
$target_image = ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
ImageDestroy($base_image);
return $target_image;
}
示例11: PrintReport
function PrintReport()
{
//建立画布大小
$this->IMAGE = ImageCreate($this->X, $this->Y);
//设定画布背景色
$background = ImageColorAllocate($this->IMAGE, $this->R, $this->G, $this->B);
if ($this->TRANSPARENT == "1") {
//背影透明
Imagecolortransparent($this->IMAGE, $background);
} else {
//如不要透明时可填充背景色
ImageFilledRectangle($this->IMAGE, 0, 0, $this->X, $this->Y, $background);
}
//参数字体文小及颜色
$this->FONTCOLOR = ImageColorAllocate($this->IMAGE, 255 - $this->R, 255 - $this->G, 255 - $this->B);
switch ($this->REPORTTYPE) {
case "0":
break;
case "1":
$this->imageColumnS();
break;
case "2":
$this->imageColumnH();
break;
case "3":
$this->imageLine();
break;
case "4":
$this->imageCircle();
break;
}
$this->printXY();
$this->printAll();
}
示例12: 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);
}
示例13: image
private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4, $color = array())
{
$h = count($frame);
$w = strlen($frame[0]);
$imgW = $w + 2 * $outerFrame;
$imgH = $h + 2 * $outerFrame;
$base_image = ImageCreate($imgW, $imgH);
$col[0] = ImageColorAllocate($base_image, 255, 255, 255);
if ($color) {
$col[1] = ImageColorAllocate($base_image, $color[0], $color[1], $color[2]);
} else {
$col[1] = ImageColorAllocate($base_image, 0, 0, 0);
}
imagefill($base_image, 0, 0, $col[0]);
for ($y = 0; $y < $h; $y++) {
for ($x = 0; $x < $w; $x++) {
if ($frame[$y][$x] == '1') {
ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]);
}
}
}
$target_image = ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
ImageDestroy($base_image);
return $target_image;
}
示例14: 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);
}
示例15: captcha_create
function captcha_create($text, $config)
{
global $cfg;
// anzahl der zeichen
$count = strlen($text);
// schriftarten festlegen
$ttf = $config["ttf"];
// schriftgroesse festlegen
$ttf_size = $config["font"]["size"];
// schriftabstand rechts
$ttf_x = $config["font"]["x"];
// schriftabstand oben
$ttf_y = $config["font"]["y"];
// hintergrund erstellen
$ttf_img = ImageCreate($count * 2 * $ttf_size, 2 * $ttf_size);
// bgfarbe festlegen
$bg_color = ImageColorAllocate($ttf_img, $config["bg_color"][0], $config["bg_color"][1], $config["bg_color"][2]);
// textfarbe festlegen
$font_color = ImageColorAllocate($ttf_img, $config["font_color"][0], $config["font_color"][1], $config["font_color"][2]);
// schrift in bild einfuegen
foreach (str_split($text) as $key => $character) {
// schriftwinkel festlegen
$ttf_angle = rand(-25, 25);
// schriftarten auswaehlen
$ttf_font = $ttf[rand(0, count($ttf) - 1)];
imagettftext($ttf_img, $ttf_size, $ttf_angle, $ttf_size * 2 * $key + $ttf_x, $ttf_y, $font_color, $ttf_font, $character);
}
// bild temporaer als datei ausgeben
$captcha_crc = crc32($text . $config["randomize"]);
$captcha_name = "captcha-" . $captcha_crc . ".png";
$captcha_path = $cfg["file"]["base"]["maindir"] . $cfg["file"]["base"]["new"];
imagepng($ttf_img, $captcha_path . $captcha_name);
// bild loeschen
imagedestroy($ttf_img);
}