|
|
XLII. Image functions
You can use the image functions in PHP to get the size of
JPEG, GIF,
PNG, SWF,
TIFF and JPEG2000 images, and if
you have the GD library (available at ) you will also be able to create
and manipulate images.
If you have PHP compiled with --enable-exif
you are able to work with information stored in headers of
JPEG and TIFF images. These
functions do not require GD library.
The format of images you are able to manipulate depend on the
version of gd you install, and any other libraries gd might need
to access those image formats. Versions of gd older than gd-1.6
support gif format images, and do not support png, where versions
greater than gd-1.6 support png, not gif.
In order to read and write images in jpeg format, you will need to
obtain and install jpeg-6b (available at
), and then recompile gd to
make use of jpeg-6b. You will also have to compile PHP with
--with-jpeg-dir=/path/to/jpeg-6b.
To add support for Type 1 fonts, you can install t1lib (available
at ), and then add
--with-t1lib[=dir].
User Contributed Notes Image functions |
|
27-Jun-1999 06: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.
|
|
22-Jul-1999 12: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 !!
|
|
09-Sep-1999 06: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.
|
|
24-Oct-1999 05: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.
|
|
26-Jul-2000 07: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:-')
|
|
28-Jul-2000 01: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 ;-)
|
|
13-Oct-2000 07: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.
|
|
17-Oct-2000 11: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.
|
|
20-Dec-2000 05:09 |
|
GD can only create 256 colors images
|
|
30-Jan-2001 04: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
|
|
13-Feb-2001 12: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 05: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
|
|
12-Mar-2001 04: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".
|
|
13-Mar-2001 06:59 |
|
PHP4+GD1.8.4 does not compile correctly with Freetype 2. Use Freetype 1.3.1
instead.
|
|
21-Mar-2001 10: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.
|
|
19-May-2001 07: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
?>
|
|
24-May-2001 04: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
|
|
26-Jun-2001 02: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>
|
|
06-Aug-2001 06: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 ...
|
|
09-Aug-2001 01: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!
|
|
17-Aug-2001 05: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
|
|
25-Sep-2001 11: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
|
|
09-Oct-2001 01: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.
|
|
10-Oct-2001 08: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.
|
|
19-Oct-2001 02: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"
|
|
05-Nov-2001 09: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 !!
|
|
05-Dec-2001 02: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.
|
|
14-Dec-2001 10: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).
|
|
10-Jan-2002 03: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 11: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
|
|
02-Feb-2002 09: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;
}
|
|
10-Mar-2002 02: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.
|
|
12-Mar-2002 09: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.
|
|
12-Mar-2002 05: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);
?>
|
|
14-Mar-2002 03: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).
|
|
26-Mar-2002 01:12 |
|
For those looking for more information on how to get GD 2 working with PHP,
see the steps suggested by Rasmus at:
|
|
27-Mar-2002 03: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! :)
|
|
30-Apr-2002 09: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.
|
|
09-May-2002 09: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)
|
|
16-May-2002 11: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 01: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.
|
|
02-Jul-2002 05:27 |
|
PHP/GD is not configured default with GIF support on Red Hat 7.3 / Apache
1.23
|
|
|
| |