Web студия "GrandView"
  Главная   Написать Контакты
   
   
О проекте
Руководство php
 

imagecreate

(PHP 3, PHP 4, PHP 5)

imagecreate -- Create a new palette based image

Описание

resource imagecreate ( int width, int height )

imagecreate() returns an image identifier representing a blank image of specified size.

We recommend the use of imagecreatetruecolor().

Список параметров

width

The image width

height

The image height

Возвращаемые значения

Returns an image resource identifier on success, FALSE on errors.

Примеры

Пример 1. Creating a new GD image stream and outputting an image.

<?php
header
("Content-type: image/png");
$im = @imagecreate(110, 20)
    or die(
"Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5"A Simple Text String", $text_color);
imagepng($im);
imagedestroy($im);
?>

Результатом выполнения данного примера будет что-то подобное:

Смотрите также

imagedestroy()
imagecreatetruecolor()



imagecreatefromgd2> <imagecopyresized
Last updated: Sat, 27 Jan 2007
 
add a note add a note User Contributed Notes
imagecreate
scottlindh pwnd at hushmail dot com
19-Aug-2007 10:40
to install on UBUNTU do the following..

sudo apt-get install php5-gd

After installing the package I restarted the apache

sudo /etc/init.d/apache reload

goto love ubuntu...
Sohel Taslim
25-Jul-2007 12:22
It is easy and simple example to convert Text to Image with selected font.
It helps me to display Bangla text as image when users have no installed bangla font.

I hope it can help you too!

<?php
//Kip the font file together or write proper location.
makeImageF("Life in PHP.","CENTURY.TTF");

function
makeImageF($text, $font="CENTURY.TTF", $W=200, $H=20, $X=0, $Y=0, $fsize=18, $color=array(0x0,0x0,0x0), $bgcolor=array(0xFF,0xFF,0xFF)){
       
   
$im = @imagecreate($W, $H)
        or die(
"Cannot Initialize new GD image stream");
       
   
$background_color = imagecolorallocate($im, $bgcolor[0], $bgcolor[1], $bgcolor[2]);        //RGB color background.
   
$text_color = imagecolorallocate($im, $color[0], $color[1], $color[2]);            //RGB color text.
           
   
imagettftext($im, $fsize, $X, $Y, $fsize, $text_color, $font, $text);
   
   
header("Content-type: image/gif");               
    return
imagegif($im);
}

?>
Pawka
14-Apr-2007 01:31
To make the gd library available for Apache2/mod_php on Fedora Linux the following commands are required:
1) yum install php-gd
2) /etc/init.d/httpd restart
php dot net at kingsquare dot nl
07-Jan-2007 03:02
To create an image from a PSD file, you can use imagecreatefrompsd(). It is available for download here: http://www.kingsquare.nl/phppsdreader/ . It returns a resource like the other ImageCreateFrom - functions
tc_ at anti dot gmx dot ch dot spam
19-Sep-2006 04:50
Small piece of code to display a preview of a file in an image (usefull for thumbnail view of a folder etc.)

<?php
$file
= "test.txt"; //FILEADDRESS
$size = "100"; //IMAGE SIZE
$data = file($file);
$im = @ imagecreate($size, $size) or die();
$bc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
$lines = (int) $size / 10;
for (
$t = 0; $t < $lines; $t++)
{
   
imagestring($im, 3, 4, 4, $data[$t], $tc);
   
imagestring($im, 3, 4, 4 + ($t * 10), $data[$t], $tc);
}
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
?>

Maybe it will be usefull for somebody.
Ortreum
07-Sep-2006 04:45
Use image as javascript test

There are two files - an image and an executive file. The image is loaded if the JavaScript is enabled. After (!) the page is loaded $_SESSION['js'] + 0 is 0 or 1.

the image (js.img.php):
<?php
session_start
();
$_SESSION['js'] = 1;
header('Content-type: image/gif');
imagegif($im = imagecreate(1, 1));
imagedestroy($im);
?>

the html file (file.php):
<html>
<head>
<!--
<script type="text/javascript">
    var img = new Image();
    img.src = "js.img.php";
</script>
-->
</head>
<body>
<?php
if ($_SESSION['js'] . '' == '') echo 'Not checked for JavaScript.';
else if (
$_SESSION['js'] + 0 == 0) echo 'JavaScript is disabled.';
if (
$_SESSION['js'] + 1 == 1) echo 'JavaScript is enabled.';
?>
</body>
</html>

There are much more hidden actions that you can do by "pictures".
help at nanomc dot com
08-Nov-2005 11:29
// A simple XY graph

<html>
<head>
       
 <title>XY Graph</title>

<h2>Practice XY Graph</h2>
</head>
<body>

<?php
$left
= 0;
$top = 0;
$x_size = 400;
$y_size = 400;

$char_width = 8;
$char_height = 11;

$x_start = $x_left + 100;
$y_start = $top + $char_height * 1.5;
$x_end = $x_start + $x_size;
$y_end = $y_start + $y_size;
$right = $x_start + $x_size + 40;
$bottom = $y_start + $y_size + $char_height * 1.5;

$graph_n = 100;
for(
$i = 0; $i < $graph_n; $i++ )
    {
   
$graph_x[$i] = $i;
   
$graph_y[$i] = $i * $i;
    }

   
$min_x = 9e99;
   
$min_y = 9e99;
   
$max_x = -9e99;
   
$max_y = -9e99;

   
$avg_y = 0.0;
   
    for(
$i = 0; $i < $graph_n; $i++ )
        {
        if(
$graph_x[$i] < $min_x )
           
$min_x = $graph_x[$i];

        if(
$graph_x[$i] > $max_x )
           
$max_x = $graph_x[$i];

        if(
$graph_y[$i] < $min_y )
           
$min_y = $graph_y[$i];

        if(
$graph_y[$i] > $max_y )
           
$max_y = $graph_y[$i];

       
$avg_y += $graph_y[$i];
        }
   
   
$avg_y = $avg_y / $graph_n;

   
$min_x = 0;
   
$min_y = 0;
   
$max_x += $max_x * 0.05;
   
$max_y += $max_y * 0.05;

$image = ImageCreate($right - $left, $bottom - $top);
$background_color = imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 233, 14, 91);

$grey = ImageColorAllocate($image, 204, 204, 204);
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
$red = imagecolorallocate($image, 255, 0, 0);

imagerectangle($image, $left, $top, $right - 1, $bottom - 1, $black );
imagerectangle($image, $x_start, $y_start, $x_end, $y_end, $grey );

for(
$i = 0; $i < $graph_n; $i++ )
   {
  
$pt_x = $x_start + ($x_end-$x_start)*($graph_x[$i]-$min_x)/($max_x-$min_x);
  
$pt_y = $y_end - ($y_end - $y_start)*($graph_y[$i]-$min_y)/($max_y-$min_y);

 
//  imagesetpixel( $image, $pt_x, $pt_y, $black );
  
imagechar($image, 2, $pt_x - 3, $pt_y - 10, '.', $black);
   }

$string = sprintf("%2.5f", $max_y);
imagestring($image, 4, $x_start - strlen($string) * $char_width, $y_start - $char_width, $string, $black);

$string = sprintf("%2.5f", $min_y);
imagestring($image, 4, $x_start - strlen($string) * $char_width, $y_end - $char_height, $string, $black);

$string = sprintf("%2.5f", $min_x);
imagestring($image, 4, $x_start - (strlen($string) * $char_width)/2, $y_end, $string, $black);
   
$string = sprintf("%2.5f", $max_x);
imagestring($image, 4, $x_end - (strlen($string) * $char_width) / 2, $y_end, $string, $black);

$x_title = 'x axis';
$y_title = 'y axis';

imagestring($image, 4, $x_start + ($x_end - $x_start) / 2 - strlen($x_title) * $char_width / 2, $y_end, $x_title, $black);

imagestring($image, 4, $char_width, ($y_end - $y_start) / 2, $y_title, $black);

header('Content-type: image/png');
$filename = sprintf("%d.png", time());
ImagePNG($image,$filename);
ImageDestroy($image);

printf("<img src='%s'> ", $filename);
?>

</body>
</html>
DHKold
15-Jun-2005 02:52
to create an image from a BMP file, I made this function, that return a resource like the others ImageCreateFrom function:

<?php
/*********************************************/
/* Fonction: ImageCreateFromBMP              */
/* Author:   DHKold                          */
/* Contact:  admin@dhkold.com                */
/* Date:     The 15th of June 2005           */
/* Version:  2.0B                            */
/*********************************************/

function ImageCreateFromBMP($filename)
{
 
//Ouverture du fichier en mode binaire
  
if (! $f1 = fopen($filename,"rb")) return FALSE;

 
//1 : Chargement des ent
Новости
11 июля 2007
Сайт запущен
© 2007 info@grandviewstudio.com

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 324

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 330
Z058440144362 Z348613067571