PHP: K�pmanipul�l� f�ggv�nyek - Manual
PHP  
downloads | documentation | faq | getting help | mailing lists | | php.net sites | links 
search for in the  
previousob_iconv_handlerexif_imagetypenext
Last updated: Fri, 30 Aug 2002
view the printer friendly version or the printer friendly version with notes or change language to English | Brazilian Portuguese | Chinese | Czech | Dutch | Finnish | French | German | Italian | Japanese | Korean | Polish | Romanian | Russian | Spanish | Swedish | Turkish

XLI. K�pmanipul�l� f�ggv�nyek

A PHP k�pmanipul�l� f�ggv�nyeit haszn�lhatod JPEG, GIF, PNG �s SWF k�pek m�reteinek lek�rdez�s�re, �s ha van GD k�nyvt�rad, mely a c�men �rhet� el, tudsz vele k�peket k�sz�teni �s manipul�lni.

Tartalom
exif_imagetype -- Determine the type of an image
exif_read_data -- Read the EXIF headers from JPEG or TIFF. This way you can read meta data generated by digital cameras.
exif_thumbnail -- Retrieve the embedded thumbnail of a TIFF or JPEG image
GetImageSize -- Egy GIF, JPEG, PNG vagy SWF k�p m�ret�t adja vissza
image_type_to_mime_type -- Get Mime-Type for image-type returned by getimagesize, exif_read_data, exif_thumbnail, exif_imagetype
image2wbmp -- Output image to browser or file
imagealphablending -- Set the blending mode for an image
ImageArc -- Egy ellipszisdarabot rajzol
ImageChar -- Egy karaktert rajzol v�zszintesen
ImageCharUp -- Egy karaktert rajzol f�gg�legesen
ImageColorAllocate -- Egy sz�nt foglal le egy k�pben
ImageColorAt -- Egy k�ppont sz�n�nek index�t adja vissza
ImageColorClosest --  Az adott sz�nhez legk�zelebb �ll� sz�n index�t adja vissza
imagecolorclosestalpha -- Get the index of the closest color to the specified color + alpha
imagecolorclosesthwb --  Get the index of the color which has the hue, white and blackness nearest to the given color
ImageColorDeAllocate --  Egy sz�nt szabad�t fel egy k�pb�l
ImageColorExact -- A megadott sz�n palettabeli index�t adja vissza
imagecolorexactalpha -- Get the index of the specified color + alpha
ImageColorResolve --  Az adott sz�n, vagy ahhoz legk�zelebbi sz�n palettaindex�t adja vissza.
imagecolorresolvealpha --  Get the index of the specified color + alpha or its closest possible alternative
ImageColorSet --  Adott index� palettasz�n megv�ltoztat�sa
ImageColorsForIndex -- Adott index� sz�n RGB komponensei
ImageColorsTotal --  A k�p palett�j�ban lev� sz�nek sz�m�t adja
ImageColorTransparent -- Egy sz�nt �tl�tsz�nak defini�l
ImageCopy --  K�p egy r�sz�t m�solja
imagecopymerge -- Copy and merge part of an image
imagecopymergegray -- Copy and merge part of an image with gray scale
imagecopyresampled -- Copy and resize part of an image with resampling
ImageCopyResized -- M�solja �s �tm�retezni egy k�p r�szlet�t
ImageCreate -- Egy �j k�pet hoz l�tre
imagecreatefromgd2 -- Create a new image from GD2 file or URL
imagecreatefromgd2part -- Create a new image from a given part of GD2 file or URL
imagecreatefromgd -- Create a new image from GD file or URL
ImageCreateFromGif -- Fileb�l vagy URL-b�l �j k�pet hoz l�tre
ImageCreateFromJpeg -- Fileb�l vagy URL-b�l �j k�pet hoz l�tre
ImageCreateFromPng -- F�jlb�l vagy URL-b�l �j k�pet hoz l�tre
imagecreatefromstring -- Create a new image from the image stream in the string
imagecreatefromwbmp -- Create a new image from file or URL
imagecreatefromxbm -- Create a new image from file or URL
imagecreatefromxpm -- Create a new image from file or URL
imagecreatetruecolor -- Create a new true color image
ImageDashedLine -- Szaggatott vonalat rajzol
ImageDestroy -- Megsemmis�t egy k�pet
imageellipse -- Draw an ellipse
ImageFill -- Z�rt ter�let kifest�se
imagefilledarc -- Draw a partial ellipse and fill it
imagefilledellipse -- Draw a filled ellipse
ImageFilledPolygon -- Kit�lt�tt soksz�get rajzol
ImageFilledRectangle -- Kit�lt�tt t�glalapot rajzol
ImageFillToBorder -- Kit�lt�s adott hat�rol� sz�nig
ImageFontHeight -- Adott bet�t�pus magass�ga
ImageFontWidth -- Adott bet�t�pus sz�less�ge
imageftbbox -- Give the bounding box of a text using fonts via freetype2
imagefttext -- Write text to the image using fonts using FreeType 2
ImageGammaCorrect --  A GD k�pre gamma korrekci�t alkalmaz
imagegd2 -- Output GD2 image to browser or file
imagegd -- Output GD image to browser or file
ImageGIF -- Kirajzol egy k�pet, vagy f�jlba menti
ImageInterlace -- Interlace bit �ll�t�sa
ImageJPEG -- Kirajzol egy k�pet, vagy f�jlba menti
ImageLine -- Vonalat rajzol
ImageLoadFont -- Bet�lt egy bet�k�szletet
imagepalettecopy -- Copy the palette from one image to another
ImagePng --  Kirajzol PNG egy k�pet, vagy f�jlba menti
ImagePolygon -- Soksz�get rajzol
ImagePSBBox --  Sz�veg k�r� rajzolt legkisebb t�glalap m�reteit adja PostScript Type1 bet�k�szletet haszn�lva
ImagePSCopyFont --  Make a copy of an already loaded font for further modification
ImagePSEncodeFont --  Megv�ltoztatja a bet�k�szlet egy karakterk�dol�si vektor�t
ImagePsExtendFont --  Sz�th�z vagy zsugor�t egy bet�k�szletet
ImagePSFreeFont -- Egy PostScript Type 1 bet�t�pus �ltal haszn�lt mem�ri�t szabad�t fel
ImagePSLoadFont -- F�jlb�l bet�lt egy PostScript Type 1 bet�t�pust
ImagePsSlantFont --  D�nt egy bet�k�szletet
ImagePSText --  Egy k�pbe PostScript Type1 t�pus� sz�veget �r
ImageRectangle -- T�glalapot rajzol
imagesetbrush -- Set the brush image for line drawing
ImageSetPixel -- Egy pont sz�n�t megv�ltoztatja
imagesetstyle -- Set the style for line drawing
imagesetthickness -- Set the thickness for line drawing
imagesettile -- Set the tile image for filling
ImageString -- Karakterl�ncot �r ki (v�zszintesen)
ImageStringUp -- Ki�r egy karakterl�ncot lentr�l fel [mint ahogy a :-)-t kell n�zni]
ImageSX -- K�p sz�less�ge
ImageSY -- K�p magass�ga
imagetruecolortopalette -- Convert a true color image to a palette image
ImageTTFBBox --  TruType bet�t�pus� sz�veg befoglal� t�glalapj�t adja vissza.
ImageTTFText --  TrueType t�pus� sz�veget �r ki egy k�pre
imagetypes -- Return the image types supported by this PHP build
imagewbmp -- Output image to browser or file
iptcembed -- Embed binary IPTC data into a JPEG image
iptcparse --  Parse a binary IPTC block into single tags.
jpeg2wbmp -- Convert JPEG image file to WBMP image file
png2wbmp -- Convert PNG image file to WBMP image file
read_exif_data -- Reads header information stored in TIFF and JPEG images
User Contributed Notes
K�pmanipul�l� f�ggv�nyek
add a note about notes
[email protected]
27-Jun-1999 07:18

Noteworthy: unless you get and install GD from the URL provided, and configure PHP using --with-gd=PATH, these image drawing functions will not work. They are not part of the "base" build.
[email protected]
22-Jul-1999 01:31

I hope this can help hours of investigation for people how doen't know how to do it:
To simulate a gif from a php3 file:

// create the image
$gif = ImageCreate(200,200);
$bg = ImageColorAllocate($gif,0,0,0);
$tx = ImageColorAllocate($gif,255,128,128);
ImageFilledRectangle($gif,0,0,200,200,$bg);
ImageString($gif,3,70,90,"it works !",$tx);

// send the image
header("content-type: image/gif");
ImageGif($gif);

That's all folks !!

[email protected]
09-Sep-1999 07:06

It is easy to use ImageMagick to generate images dynamically in php3. Here is an example:

<?php
Header("Content-type: image/gif"); passthru("/opt/x11/bin/convert -crop 0x0 -bordercolor white -border 10x10 inputfile.gif GIF:-
?>

The header is important, the passthru functions means binary data will be safe, and "-" means ImageMagick will print to stdout instead of saving to a file.

[email protected]
24-Oct-1999 06:55

If you compiled in T1lib, there are three functions not documented here:
integer imagepscopyfont(integer font_identifier)
//Make a copy of a font for purposes like extending or re-encoding

boolean imagepsextendfont(integer font_identifier, double extend)
// Extend or or condense (if extend < 1) a font
// It extents a font horizontally--makes its characters wider
// Extension is not cumulative.

boolean imagepsslantfont(integer font_identifier, double slant)
// Slant a font
// The slant-factor s tells the rastering algorithm to advance the
// x-coordinate of a given point by the product of s with the
// y-coordinate of that point.

Read the docs for T1lib and the gd.c source if you need more info.

[email protected]
26-Jul-2000 08:24

After a day's worth of hassle, I discovered that the solution to making gifs (no LZW so it's legal) is to use ImageMagick. You can get it at


The following code works:

<?php
$fonts=Array('coolvet.ttf','doodle.ttf','gas.ttf',
'guinea.ttf','hijinx.ttf','hypno.ttf');
$fontname='/home/eric/public_html/imagephp/'.$fonts[$font];
list($llx,$lly,$lrx,$lry,$urx,$ury,$ulx,$uly)=imageTTFbbox($size,0,$fontname,$text);
$id=imagecreate(abs($urx-$ulx)+10,abs($lly-$ury)+8);
$black= ImageColorAllocate($id, 0, 0, 0);
$white= ImageColorAllocate($id, 250, 250, 250);
imagefill($id,0,0,$white);
imagettftext($id,$size,0,0,abs($ury-$lry)+2,$black,$fontname,$text);
Header("Content-type: image/gif");
ImagePNG($id,"/tmp/test.png");
passthru("/usr/local/bin/convert /tmp/test.png gif:-");
imagedestroy($id)
?>

Now if there was only a way to get ImagePNG to output to a pipe, we could use:

ImagePNG($id,'|/usr/local/bin/convert png:- gif:-')

[email protected]
28-Jul-2000 02:36

FINALLY -- here is what I had to do to compile PHP with image creation on FreeBSD4.0; I hope this is at least somewhat helpful to Linux users also:

(Notes: I used gmake instead of make, but if you don't have gmake, it should still work with 'make' and 'make install'. I used the DSO install method with Apache; I have not yet done this as a static linked install)

1. Assume X-windows, libpng, mysql, gmake and automake are already installed.

2. Install libjpeg (from
)
a) ./configure --enable-shared
b) gmake, gmake install

3. Install Freetype 1.3.1 (from )
a) ./configure --enable-shared --x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib
b) gmake, gmake install
c) if freetype creates a freetype/ directory inside /usr/local/lib, copy all contents into /usr/local/lib

4. Install zlib 1.1.3 (from )
a) ./configure --shared
b) gmake, gmake install

5. Install gd-1.8.3 (from )
a) edit Makefile for correct include and lib dirs, and uncomment the lines that enable all options, while commenting out the default lines
b) edit gd.c; remove 1st three lines (if - endif for malloc.h)
c) edit gdcache.h and ...php-src/ext/gd/gdcache.h (if exists) and replace <malloc.h> with <stdlib.h>
d) copy /usr/X11R6/include/X11 to /usr/X11R6/include/X11/X11 (gd looks recursively inside X11 to X11/*)
e) gmake, gmake install

6. Install apache-1.3.12
a) ./configure --prefix=/usr/local/apache --enable-module=all --enable-shared=max
b) gmake, gmake install

7. Install PHP 4.0.1pl2
a) ./configure --prefix=/usr/local/php4 --with-mysql --with-apxs=/usr/local/apache/bin/apxs --enable-track-vars --with-gd=/usr/local/ --with-jpeg-dir=/usr/local --with-xpm-dir=/usr/X11R6 --with-zlib-dir=shared
b) gmake, gmake install
c) sometimes I have found you need to reboot the system completely instead of just restart httpd

have fun ;-)

[email protected]
13-Oct-2000 08:10

Concerning the compilation of PHP 3.0.16 with GD 1.8.3 on Linux Mandrake 7:

It can become rather nasty to try and get things running with GD and JPEG support. We had to tweak the following things:

When calling configure for PHP, add the line
--with-gd=yes
instead of just --with-gd or --with-gd=/path/to/gd. This causes configure to find the gdImageCreateFromJpeg function.
Unfortunately, now the gdImageColorResolve function isn't found. So we changed the configure.in file around line 800 to look like this:

withval=$old_withval
LIBS="-ljpeg $LIBS"
AC_CHECK_LIB(gd,gdImageCreateFromJpeg,[AC_DEFINE(HAVE_GD_JPG)])
LIBS=$old_LIBS
if test "$ac_cv_lib_gd_gdImageCreateFromJpeg" = "yes"; then
AC_ADD_LIBRARY(jpeg)
fi

old_LIBS=$LIBS
LIBS="$LIBS -lpng -lz"
AC_CHECK_LIB(gd,gdImageCreateFromGif,[AC_DEFINE(HAVE_GD_GIF)])
AC_CHECK_LIB(gd,gdImageLzw, [AC_DEFINE(HAVE_GD_LZW)])
AC_CHECK_LIB(gd,gdImageColorResolve, [AC_DEFINE(HAVE_GD_COLORRESOLVE)])
AC_CHECK_LIB(gd,gdImageString16,[ ], [AC_DEFINE(HAVE_GD_ANCIENT)])
LIBS=$old_LIBS

dnl Say hi to the NetBSD package system!

This causes everything to be found. The first part concerning gdImageCreateFromJpeg is just in case --with-gd=yes doesn't work.

Now, configure needs to be regenerated with the new configure.in.
Do this by typing
autoconf

That's it.
Hope it helps someone out there.

[email protected]
18-Oct-2000 12:48

I've found that one of the things that most often fails when installing PHP with GD support is that the path to GD is specified wrong or not specified at all. The placement PHP considers to be GD's default install dir is not what GD considers it to be, GD will most likely be installed in /usr/local unless otherwise specified. So the parameter to pass to configure is --with-gd=/usr/local or whereever you have put GD.
[email protected]
20-Dec-2000 06:09

GD can only create 256 colors images
bene[nospam]@iolvegas.com
30-Jan-2001 05:23

If you get these errors while trying to compile:

gd.c: In function `php_if_imagecreatefromgif':
gd.c:709: `gdImageCreateFromGif' undeclared (first use in this function)
gd.c:709: (Each undeclared identifier is reported only once
gd.c:709: for each function it appears in.)
gd.c:709: `gdImageCreateFromGifCtx' undeclared (first use in this function)
gd.c: In function `php_if_imagegif':
gd.c:891: `gdImageGif' undeclared (first use in this function)

Then you are using an old version of gd.h and probably didn't specify the PATH on --with-gd ... Slackware on my systems had an old gd.h hidden away ...

Be warned!

./configure --with-gd=/usr/local

[email protected]
13-Feb-2001 01:59

Things needed for gd integration into php / apache running Solaris 7:
before starting check your env variables
comment out LD_LIBRARY_PATH
and make sure that /usr/ccs/bin is before /usr/ucb in your PATH ( this is for Libpng )
Download packages from
jpeg-6b-sol7-sparc-local.gz
libpng-1.0.2-sol7-sparc-local.gz
zlib-1.1.3-sol7-sparc-local.gz zlib
use pkgadd -d to install each of these packages into /usr/local
and gd-1.8.3.tar.gz from

unpack zlib then libpng then jpeg... just make sure to do zlib before libpng
( not sure if it matters with the packages ? )
unpack gd
modify the Makefile, to use JPEG like this:
CFLAGS= -O -DHAVE_JPEG and
LIBS= -lm -lgd -lpng -lz -ljpeg
now configure php
./configure --with-apache=../apache_1.3.14/ --with-oci8 --enable-track-vars --with-gd=/usr/local �with-jpeg-dir=/usr/local
make
make install
now configure apache
./configure �activate-module=src/modules/php4/libphp4.a
make

07-Mar-2001 06:29
When using ImageGif( $im ) it sends the output directly to the browser. to prevent this from happening and also to be able to save your new image to a database for example use ob_start(), ob_get_contents(), and ob_end_clean()

ex:
<?php
function ResizeGif( $image, $newWidth, $newHeight){

//Open the gif file to resize
$srcImage = ImageCreateFromGif( $image );

//obtain the original image Height and Width
$srcWidth = ImageSX( $srcImage );
$srcHeight = ImageSY( $srcImage );


// the follwing portion of code checks to see if
// the width > height or if width < height
// if so it adjust accordingly to make sure the image
// stays smaller then the $newWidth and $newHeight

if( $srcWidth < $srcHeight ){

$destWidth = $newWidth * $srcWidth/$srcHeight;
$destHeight = $newHeight;
}else{

$destWidth = $newWidth;
$destHeight = $newHeight * $srcHeight/$srcWidth;
}


// creating the destination image with the new Width and Height
$destImage = imagecreate( $destWidth, $destHeight);

//copy the srcImage to the destImage
ImageCopyResized( $destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight );

//create the gif
ImageGif( $destImage );


//fre the memory used for the images
ImageDestroy( $srcImage );
ImageDestroy( $destImage );

}

//save output to a buffer
ob_start();

//Resize image ( will be stored in the buffer )
ResizeGif( "/where/image/is/image.gif", "150", "150");

//copy output buffer to string
$resizedImage = ob_get_contents();

//clear output buffer that was saved
ob_end_clean();


//write $resizedImage to Database, file , echo to browser whatever you need to do with it

Also do not put Header() between ob_start and ob_end_clean() because they will still be sent. $resizedImage is the resized image had there been no ob function calls ResizeGif() would have sent the output to the browser.I hope this helps some people with databases that want to store there image

Dave

[email protected]
12-Mar-2001 05:12

For those of you who wants to compile PHP as Apache static module but failed in compiling Apache (undefined some PNG_XXX) functions, try re-ordering the -l parameters in Apache Makefiles (there are several) so that "-lgd is loaded before -lpng".
[email protected]
13-Mar-2001 07:59

PHP4+GD1.8.4 does not compile correctly with Freetype 2. Use Freetype 1.3.1 instead.
[email protected]
21-Mar-2001 11:00

If you've tried a few versions of the required libraries remove your config.cache from your php source dir and rerun configure ; make clean ; make. The cache seems to get stale sometimes from the changes.

If you're getting missing symbols when you try to compile apache your link order may be screwy. gcc on FreeBSD 4.x seems to link libraries in the opposite order they are specified on the command line (right to left), twiddle with your apache/src/Makefile to change the link order. -lttf -lgd -lpng -lz -ljpeg seems to be sane, YMMV.

[email protected]
19-May-2001 08:31

Improved version of ResizeGif given by tjhunter with Height % Widht.

<?php
/* ResizeGif with (height % width) */
function RatioResizeImg( $image, $newWidth, $newHeight){

//Open the gif file to resize
eregi(".(.*)$",$image,$regs);
switch($regs[1]){
case "gif": $srcImage = ImageCreateFromGIF( $image ); break;
case "jpg": $srcImage = ImageCreateFromJPEG( $image ); break;
case "png": $srcImage = ImageCreateFromPNG( $image ); break;
default: $srcImage = ImageCreateFromGIF( $image ); break;}



//obtain the original image Height and Width
$srcWidth = ImageSX( $srcImage );
$srcHeight = ImageSY( $srcImage );


// the follwing portion of code checks to see if
// the width > height or if width < height
// if so it adjust accordingly to make sure the image
// stays smaller then the $newWidth and $newHeight

$ratioWidth = $srcWidth/$newWidth;
$ratioHeight = $srcHeight/$newHeight;

if( $ratioWidth < $ratioHeight){

$destWidth = $srcWidth/$ratioHeight;
$destHeight = $newHeight;
}else{

$destWidth = $newWidth;
$destHeight = $srcHeight/$ratioWidth;
}


// creating the destination image with the new Width and Height
$destImage = imagecreate( $destWidth, $destHeight);

//copy the srcImage to the destImage
ImageCopyResized( $destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight );

//create the gif
ImageGif( $destImage );


//fre the memory used for the images
ImageDestroy( $srcImage );
ImageDestroy( $destImage );

}

//save output to a buffer
ob_start();

//Resize image ( will be stored in the buffer )
ResizeGif( "/where/image/is/image.gif", "150", "150");

//copy output buffer to string
$resizedImage = ob_get_contents();

//clear output buffer that was saved
ob_end_clean();


//write $resizedImage to Database, file , echo to browser whatever you need to do with it
?>

[email protected]
24-May-2001 05:45

I build menus using image functions. I noticed that even if you preload the images, some do not always load. In addition the image generation puts a load on the server... the answer? Cache Control headers. These headers will cause IE and Netscape to load all images correctly and also force the proxys and web caches to cache them, allowing your pages to render correctly, AND save you lots of cycles: ) These headers tell both the browser and the ISP caches/proxys to cache the images.

Here is the code:

Header ("Last-Modified: " . gmdate("D, d M Y H:i:s",mktime (0,0,0,1,1,2000)) . " GMT"); // Date in the past
Header ("Expires: Mon, 26 Jul 2040 05:00:00 GMT"); // In other words... never expire the image
Header ("Cache-Control: max-age=10000000, s-maxage=1000000, proxy-revalidate, must-revalidate");//Cache-Control header is ESSENTIAL for forcing Netscape to load all images!... and telling the ISP caches to do the same in this case cache for 1 million seconds.

These headers may or may not be redundant... any input is welcome.

In addition, it is essential for proxys and ISP caches that your re-used images have the same url... IE create a generic image creation script, and feed it parameters. This way your
Home link image has the same url on all of your pages... This will make your images more proxy/cacheserver cache AND browser cache friendly.

thx,
Neil

[email protected]
26-Jun-2001 03:27

<html>
<head>
</head>
<body>
<?
// USING A DATABASE TO CREATE BARS OF RECORS GROUP BY FIELD PROMOCION
// DIAA = DATABASE TABLE / PROMOCION = FIELD FILLED WITH YEAR VALUE ( NUMERIC )
// USING ImageGif, ONLY AVAILABLE IN MY SERVER, YOU CAN USE PNG

// OPEN DATABASE
mysql_pconnect("localhost","user","password") or die("Unable to connect to SQL server");
mysql_select_db("database") or die("Unable to select database");

// SELECT AND FILL VALUES
$varsqlstr = "SELECT * FROM DIAAA ORDER BY PROMOCION ";
$result = mysql_query($varsqlstr);
$row = mysql_fetch_array($result);

//INITIALIZE VARS

$CUENTA = 0;
$TOTAL = 0;
$PROMO = $row[PROMOCION];

// LOOP TO COUNT AND PRINT ( IF CONDITION )
for ($i = 1; $i <= (mysql_num_rows($result) + 1) ; $i++){
if ($PROMO == $row[PROMOCION]) {
$CUENTA = $CUENTA + 1;
$row = mysql_fetch_array($result);
} else {
$CUENTA2 = $CUENTA * 5;
$pic=ImageCreate(&$CUENTA2,10);
$col1=ImageColorAllocate($pic,200,200,200);
$col2=ImageColorAllocate($pic,0,127,192);
ImageFilledRectangle($pic,0,0,&$CUENTA2,10,$col2);
ImageGif($pic, $PROMO . ".gif");
ImageDestroy($pic);
echo '<img src="' . $PROMO . '.gif" border=2> <FONT face=Arial size=2> ' . $CUENTA . ' Ptos. / Prom. ' . $PROMO . '</FONT>
';
$TOTAL= $TOTAL + $CUENTA;
$CUENTA = 0;
$PROMO = $row[PROMOCION];
$CUENTA = $CUENTA + 1;
$row = mysql_fetch_array($result);
}
}

mysql_free_result($result);

?>

</body>
</html>

[email protected]
06-Aug-2001 07:28

imageTTF* sure don't work with relativ pathes any more in PHP 4.06, they even don't take win-style absolute pathes (starting with drive letter).
Moreover the geometry information of imageTTFbbox has changed and the color management, probably for all image-fcts.
Actually not a good example of downward compatibility ...

[email protected]
09-Aug-2001 02:44

PNG vs. GIF:

I know some of you are looking for
the old distribution that had GIF
support, but I should point out a few
things: Any of the new browsers
support PNGs, and PNGs are smaller
and look better than the equivalent
GIFs. Time to move on to PNG!

[email protected]
17-Aug-2001 06:54

For compliling the TTF support with GD, the option have changed and was buggy.
use :
--enable-gd-native-tt(And not --enable-gd-native-ttf as help say)

This work on debian potato with GD 1.8.4

[email protected]
26-Sep-2001 12:23

GD-2.0.1 and PHP

0. Make sure you have libjpeg and libpng installed
1. Grab GD-2.0.1.
2. tar zxvf gd-2.0.1.tar.gz
3. cd gd-2.0.1
4. Edit the Makefile and change the LIBS line to be:
LIBS=libgd.a -lpng -lz -ljpeg -lfreetype -lm
5. make libgd.a (don't need to do a make install)
6. Now build PHP using these flags:
--with-gd=/home/<you>/gd-2.0.1
--with-freetype-dir=/usr
--enable-gd-native-ttf (for PHP 4.0.6 leave off trailing 'f')
--enable-gd-imgstrttf
--with-jpeg-dir=/usr
--with-png-dir=/usr
--with-zlib

[email protected]
09-Oct-2001 02:12

PNG currently supports 16-bits per RGB- color (so 48-bit color), and an alpha-channel. There is also a 16-bit color-mode (with alpha) and a 16-but greyscale-mode. Have not tested yet whether GD can import these.
[email protected]
10-Oct-2001 09:56

>How do I install FreeType on win32 so that it works with php?

I've got quite many questions about this problem I posted earlier.

I tried it again and I noticed that Windows doesn't even need Freetype to use TTFs, just use unix-type path, where "root" is the drive php executable is in. Ie. if path to your font is C:\fonts\font.ttf you should use /fonts/font.ttf insteads.

[email protected]
19-Oct-2001 03:14

With GD 2 and PHP 4.06 on win 2000, the TTF fonts need to be on the drive where the script is called from, not where PHP is installed.

I have PHP installed on drive C:. The scripts are on drive Q:. The fonts must be in stalled on Q:.

eg. The fonts are installed in "Q:\fonts" and must be referenced by "/fonts/<fontname>.ttf"

[email protected]
05-Nov-2001 10:10

Thanks for the notes on testing gd support in the distribution! It did save me a lot of time! Just an update, though. Your code didn't work right off the bat for my system, because later versions of PHP may not support GIF format due to 'copyright stuff'. However, it's easy enough to change the code to output as JPEG or PNG or whatever. For example, to test JPEG support instead:

// create the image
$gif = ImageCreate(200,200);
$bg = ImageColorAllocate($gif,0,0,0);
$tx = ImageColorAllocate($gif,255,128,128);
ImageFilledRectangle($gif,0,0,200,200,$bg);
ImageString($gif,3,70,90,"it works !",$tx);

// send the image
header("content-type: image/jpeg");
ImageJPEG($gif);

That's all folks !!

[email protected]
05-Dec-2001 03:01

There's a bug in GD2 < 2.0.2 that prevents antialiasing from working properly. The fix for this should be in gd-2.0.2 if the GD people get around to it. This isn't a bug in php.
[email protected]
14-Dec-2001 11:26

To use freetype2 with TTF functions you need to specify

--with-freetype-dir

AND

--with-ttf

for your build (the output of configure seems as if you don't have to specify --with-ttf but you need to).

[email protected]
10-Jan-2002 04:55

Want to be able to open gifs?

In the www.php4win.de build of php there is a dll called php_gd_gif.dll. Rename this to php_gd.dll and move it into your extensions directory.

*Make sure you back up the old dll!*

31-Jan-2002 12:51
To check for GD support, you can do something like:

if(function_exists('imagetypes'))
echo 'GD is loaded';
else
echo 'GD is not loaded';

Note that many of the other functions listed here are defined regardless of wether GD is loaded or not. imagetypes() seems to be a safe one to check for now.

Enjoy

[email protected]
02-Feb-2002 10:57

If you ever want to resize a picture (maybe in order to create a thumbnail), this small function
should help you. It also gives you an idea of how some of the basic image functions of PHP can be
used.

/* resizeToFile resizes a picture and writes it to the harddisk
*
* $sourcefile = the filename of the picture that is going to be resized
* $dest_x = X-Size of the target picture in pixels
* $dest_y = Y-Size of the target picture in pixels
* $targetfile = The name under which the resized picture will be stored
* $jpegqual = The Compression-Rate that is to be used
*/

function resizeToFile ($sourcefile, $dest_x, $dest_y, $targetfile, $jpegqual)
{


/* Get the dimensions of the source picture */
$picsize=getimagesize("$sourcefile");

$source_x = $picsize[0];
$source_y = $picsize[1];
$source_id = imageCreateFromJPEG("$sourcefile");

/* Create a new image object (not neccessarily true colour) */

$target_id=imagecreatetruecolor($dest_x, $dest_y);

/* Resize the original picture and copy it into the just created image
object. Because of the lack of space I had to wrap the parameters to
several lines. I recommend putting them in one line in order keep your
code clean and readable */


$target_pic=imagecopyresampled($target_id,$source_id,
0,0,0,0,
$dest_x,$dest_y,
$source_x,$source_y);

/* Create a jpeg with the quality of "$jpegqual" out of the
image object "$target_pic".
This will be saved as $targetfile */

imagejpeg ($target_id,"$targetfile",$jpegqual);

return true;

}

[email protected]
10-Mar-2002 03:06

If your site is hosting in ISP, not your own server.
If your ISP doesn't support ImageMagick, you need to install it by yourself.
Then, you may need to put this scripts.

$im = "path.of.your.im.dir";
$convert = $im."/convert";
putenv("LD_LIBRARY_PATH=$im");
putenv("MAGICK_HOME=$im");

Setting the enviroment for the im.

[email protected]
12-Mar-2002 10:17

If u wanna use the patch for displaying chinese BIG-5 words correctly in PHP4.1.2, modify ext/gd/gdttf.c with my previous note (for php4_gdttf.c in PHP4.0.4 originally)

AND ONLY "./configure --with-gd --with-ttf" WITHOUT other related gd options.

[email protected]
12-Mar-2002 06:03

rotate image 90�>

<?

$img_sorgente="ruotami.jpg";

$size = GetImageSize($img_sorgente);
$tot_x = $size[0];
$tot_y = $size[1];

$img_risulta = ImageCreate ($tot_y,$tot_x)

$img_sorgente=ImageCreateFromJpeg($img_sorgente);

for($i_x=0;$i_x<$tot_x;$i_x++){

for($i_y=0;$i_y<$tot_y;$i_y++){

$ris_x=$tot_y-($i_y+1);
$ris_y=$i_x;

imagecopy($img_risulta, $img_sorgente, $ris_x,$ris_y,$i_x,$i_y,1,1);


} // Y

} // X

Imagejpeg($img_risulta);

?>

[email protected]
14-Mar-2002 04:14

With php 4.06 on win2000 and GD 2.0,
the only way to load and use TTF fonts is put the fonts in the same place where the php scripts are.
For example the scripts are in d:, the fonts must be in d:\fonts
You can now use all the fonts you put in this directory by typing the name of the font in your scripts (/fonts/*.ttf).

[email protected]
26-Mar-2002 02:12

For those looking for more information on how to get GD 2 working with PHP, see the steps suggested by Rasmus at:


[email protected]
27-Mar-2002 04:47

He's a function to find whether a file is an image:

function is_image($file){
$fp = fopen($file, "r");
$fcont = fread($fp, 15);
fclose($fp);
if(strstr($fcont,"PNG")){
$imagetype = "image/png";
}elseif(strstr($fcont,"GIF")){
$imagetype = "image/gif";
}elseif(strstr($fcont,"JFIF")){
$imagetype = "image/pjpeg";
}elseif(strstr($fcont,"BM")){
$imagetype = "image/bmp";
}
if(isset($imagetype)){
return $true;
}else{
return $false;
}
}

Enjoy! :)

[email protected]
30-Apr-2002 10:32

A post above mentioned using Cache Control headers to keep dynamically generated images from caching in the user's browser. I've found that, with many browsers, this doesn't help--the browser caches the image anyway.

The only way I've found to ABSOLUTELY ensure that an image is "fresh" is to put a random GET argument in the URL. Since every call to the image has a new address, the browser won't cache it.

Example:
print '<IMG SRC="MakeAnImage.php?r=' . rand(100000,999999) . '" BORDER=0>';

If you're passing ACTUAL data in the URL, just tack a random attribute on the end.

Example:
print '<IMG SRC="MakeAnImage.php?data=' . $data . '&r=' . rand(100000,999999) . '" BORDER=0>';

Easy to do, and guaranteed to work every time, on every browser.

[email protected]
09-May-2002 10:55

In reply to 'check for GD support':
Instead of looking for the existence of the 'imagetypes' function, you may go check the fact straight off with:
'$gd_loaded = extension_loaded( "gd" );'

Here's a little nice snippet to see what extensions and functions are currently available:

echo "\n\n

<table border=\"1\">\n";

$extensions = get_loaded_extensions();

foreach( $extensions as $extension )
{
echo "<tr>\n\t<td valign=\"top\"><b>$extension</b></td>\n\t<td>";
$functions = get_extension_funcs( $extension );

foreach( $functions as $function )
{
echo "$function<br-tag>";
}

echo "</td>\n</tr>\n";
}

The result is a rough table with all extensions functions listed.

Happy coding ;o)

[email protected]
16-May-2002 12:54

if your reading this part of the manual you might actually be looking for some help on making imagemagick work with php. i did anyway.
i had a really hard time figuring out why i couldnt get identify to work properly. it seemed that when i call it (with exec) i got a very strange error - unless (and this is the really strange part) i sat the switch -verbose.
eventually i figured out that identify for some reason makes a temp file in the executing dir, when running (but NOT if its in verbose-mode ?!?) ... therefore you have to change to a dir where you have writing access (like /var/tmp/)
the code below works :

$cmd = "cd /var/tmp; /usr/local/bin/identify -format "
$cmd .= " \"%m\" ".$file;
echo "<B>".$cmd."</B>\n";
$type = exec($cmd);
echo "image is of type=".$type;

aleczapka at gmx dot net
12-Jun-2002 02:21

Even if you don't intend to use PNGs, but only JPEG files with GD & PHP - you need to pass the --with-png parameter (in case PHP won't find it) to configure.
Otherwise you will get GD support = YES but functions like gdImageCreateFromJpeg won't work without png library.

[email protected]
02-Jul-2002 06:27

PHP/GD is not configured default with GIF support on Red Hat 7.3 / Apache 1.23
[email protected]
10-Jul-2002 10:33

ob_start();
phpinfo();
$phpinfo = ob_get_contents();
ob_end_clean();

$phpinfo = explode("\n",$phpinfo);

$gdversion = 0;

foreach ($phpinfo as $text) {
$parts = explode('</b>',$text);
foreach ($parts as $key=>$val) {
$parts[$key] = strip_tags($val);
}
if ($parts[0]=="GD Version") {
$gdversion = intval($parts[1]);
}
}

switch ($gdversion) {
case 1: echo "version 1.x found"; break;
case 2: echo "version 2.x found"; break;
default: echo "gd not detected, parser error possible, check phpinfo()"; break;
}

might help some of you who want to build true portable code for image manipulation/generation, and need to know aproximately what functions gd supports and more exactly what gd is installed in php (if any)

the check should be fine if phpinfo() formatting stayed consistant trough 4.x (i tested this on 4.2.1 and 4.2.0)

in 4.3 you will be able to check gd2 propperly with function_exists("imagecopyresized") for example.

hope i helped some of you :)

[email protected]
10-Jul-2002 10:43

if (PHP_VERSION >= 4.3) {
if (function_exists("imagetypes"))
{
$gdversion = 1;
if (function_exists("imagecopyresized")) {
$gdversion = 2;
}
}
}

this should be self-explanatory, for upcoming 4.3

[email protected]
10-Jul-2002 10:53

parsing phpinfo(8) would be a better idea, just change it :)
[email protected]
11-Jul-2002 07:17

To install GD on an XP machine running Apache(version whatever) and PHP:

Download the source version of PHP, even if you plan to (or already have) installed PHP using the installer version. If your installed version of PHP is older than the new source version you're downloading, you're going to need to update first.

Install PHP using the installer if necessary.

Open the source version, and copy the file "extensions/php_gd.dll" to windows\system32.

In PHP.ini, change this line:
;extension=php_gd.dll
to this
extension=php_gd.dll

Reload Apache.

Enter a phpinfo(); command and execute the script. Hit ctrl + F and type in "gd". There will now be a section dedicated to the extension.

I had tried to simply copy the dll I needed out of a new source version of PHP, but the API dates for the dll vs. PHP didn't match, so even if you plan to use the installer, you need to grab both files: installer AND source.

[email protected]
19-Jul-2002 11:05

Hey...

I'm dearly awaiting an imageCreateFromTiff() in the gd ...as I havn't yet found a workaround. exif_thumbnail() seems reluctant to fully work, resulting in a couple of warnings (so does exif_read_data()). It should be noted that Jpeg headers works
If you've experienced the same, please go and vote in the bug domain (Bug #18405).

Facts:
tiff was created using Photoshop 7.0 (Mac OSX) (tried both byte orders and all compressions)

PHP Version: 4.3.0-dev; Jul 16 2002 12:10:27

System; Win XP; Windows NT localhost 5.1 build 2600

EXIF Version: 1.4 $Id: exif.c,v 1.99 2002/07/02 22:38:37 helly Exp $

[email protected]
19-Jul-2002 12:20

In additon to [email protected], you can use php_gd2.dll for gd 2.0 support. Works with WinXP, Apache 2.0.39 and PHP 4.2.1 over sapi.
[email protected]
19-Jul-2002 03:44

Attention: php_gd2.dll seems not to work with TTFs. Here the phpinfos:

GD Support enabled
GD Version 2.0 or higher
FreeType Support enabled
FreeType Linkage with freetype
JPG Support enabled
PNG Support enabled
WBMP Support enabled

GD Support enabled
GD Version 1.6.2 or higher
FreeType Support enabled
FreeType Linkage with TTF library
JPG Support enabled
PNG Support enabled
WBMP Support enabled

[email protected]
21-Jul-2002 08:44

After finally getting the GD 2.x lib to compile into Php and work with Apache I did some tests and then found a link to some code that uses Imagemagick and the system() call. Imagemagick won hands down in quality produced. There is no speed difference that I can tell with the naked eye :)
It's nice that Php created functions with GD in mind and I don't know what the deal is with doing the same with Imagemagick but it would have saved me a lot of hours of searching and compiling if I would have known that Imagemagick could produce thumbnails without all the hassle of upgrading the GD lib.
Still, I have to thank all of those that left comments in all of these pages so that I could do it all on my own! Without subjecting our company to a fee :P
Here is the website link that got me started with the
Imagemagick:
and here is the message contents that finally got my GD 2.x lib to work with Php
---------the next few lines are copied from the guru that first wrote them----
0. Make sure you have libjpeg and libpng installed
1. Grab GD-2.0.1.
2. tar zxvf gd-2.0.1.tar.gz
3. cd gd-2.0.1
4. Edit the Makefile and change the LIBS line to be:
LIBS=libgd.a -lpng -lz -ljpeg -lfreetype -lm
5. make libgd.a (don't need to do a make install)
6. Now build PHP using these flags:
--with-gd=/home/<you>/gd-2.0.1
--with-freetype-dir=/usr
--enable-gd-native-ttf (for PHP 4.0.6 leave off trailing 'f')
--enable-gd-imgstrttf
--with-jpeg-dir=/usr
--with-png-dir=/usr
--with-zlib

[email protected]
26-Jul-2002 08:35

On RedHat 7.1 if you get a configure error when looking for XpmFreeXpmImage in libXpm it might pay to make sure both XFree86-libs*.rpm and XFree86-devel*.rpm are installed.

I only had libs installed and was pulling my hair out.

add a note about notes
previousob_iconv_handlerexif_imagetypenext
Last updated: Fri, 30 Aug 2002
show source | credits | stats | mirror sites
Copyright © 2001, 2002 The PHP Group
All rights reserved.
This mirror generously provided by:
Last updated: Wed Sep 4 00:18:56 2002 CEST