|
|
XLI. Funzioni per le immaginiIntroduzione
In PHP puoi usare delle funzioni specifiche per sapere la dimensione di un'immagine
JPEG, GIF,
PNG, SWF,
TIFF e JPEG2000.
Requisiti
Se hai installato le librerie GD (scaricabili su ) sarai anche in grado di creare immagini al volo
e di modificarle.
I formati delle immagini sulle quali potrai agire dipendono dalla versione
delle librerie GD che hai installato, e dalle altre librerie di cui
GD pu� aver bisogno per accedere a quei formati di immagine.
Versioni precedenti alla gd-1.6 supportano il formato GIF ma non quello PNG,
mentre versioni superiori alla
gd-1.6 supportano il formato PNG ma non il GIF.
Se hai compilato PHP con l'opzione --enable-exif
sarai in grado di lavorare con le informazioni memorizzate negli
header delle immagini JPEG e TIFF. Queste
funzioni non richiedono le librerie GD.
Istallazione
Per leggere e scrivere immagini in formato JPEG avrai bisogno di
installare jpeg-6b (scaricabile da ) e
quindi ricompilare le librerie GD
in modo che usino jpeg-6b. Dovrai anche
compilare PHP con l'opzione
--with-jpeg-dir=/percorso/per/jpeg-6b.
Per aggiungere il supporto per i Font Type 1 dovrai installare t1lib (scaricabile
su ), e quindi aggiungere l'opzione
--with-t1lib[=dir].
Configurazione RuntimeQuesta estensione non definisce
alcuna direttiva di configurazione Resource TypeQuesta estensione non definisce alcun tipo di risorsa. Costanti Predefinite
Queste costanti sono definite da questa estensione e
sono disponibili solo se l'estensione � stata compilata
nel PHP o se � stata caricata dinamicamente a runtime.
User Contributed Notes Funzioni per le immagini |
|
[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.
|
|
|
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 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.
|
|
|
| |