I didn't put the code in there, the hardest part was simply getting the image from the database and into an image variable that you can work with.. a call to ImageCopyResized is all you needed. I got everything figured out with my system and tested .. so here's the source:
<?php
Load our extensions
dl("pgsql.so");
dl("gd.so");
# # # # # # # # # # # # # # # # # # # # #
Load the image from the database
# # # # # # # # # # # # # # # # # # # # #
pg_connect(host, port, options, tty, dbname);
$database = pg_Connect("localhost","5432","","","photoalbum");
if ($database == False)
{
echo "Connection to database failed.";
exit;
}
$imagedata = pg_Exec($database,
"SELECT photo.data " .
"FROM photo " .
"WHERE photo.photo_id = " . $id . ";");
if ($imagedata == False)
{
header( "Content-type: text/html" );
echo "Image retrieval failed on query execution!";
exit;
}
Required for accessing large objects
pg_Exec($database, "BEGIN");
Get the OID from row_number 0 and fieldname 0 (using index value)
$imageoid = pg_Result($imagedata,0,0);
if ($imageoid == NULL) {
exit;
}
Get a file descriptor for the large object
$fd = pg_loopen($database,$imageoid,"r");
Read the large object data (image data) and store it in a string. We've assigned a limit to stop buffer overruns
$imagedata = pg_loread( $fd, 1000000 );
close the large object descriptor
pg_loclose( $fd );
Required for accessing large objects
pg_Exec($database,"COMMIT");
load the image from the database, into a string
$theimage = ImageCreateFromString( $imagedata );
Close the database
pg_close( $database );
# # # # # # # # # # # # # # # # # # # # #
Process the Image
# # # # # # # # # # # # # # # # # # # # #
Next, we need to determine what we are supposed to do here:
Here is a table that outlines the actions and parameters
Action || Parameters
==========||========
help || none
display || none
resize || destination_size_x, destination_size_y
zoom || source_x, source_y, source_size_x, source_size_y, destination_x, destination_y, destination_size_x, destination_size_y
if (!isset($action)) {
$action = "display";
}
switch( $action ) {
case "help":
display the help
echo "PHP Script Usage: <br>";
echo "<table><th>Action</th><th>Parameters</th>";
echo "<tr><td>help</td><td>none</td></tr>";
echo "<tr><td>display</td><td>none</td></tr>";
echo "<tr><td>resize</td><td>destination_size_x, destination_size_y</td></tr>";
echo "<tr><td>zoom</td><td>source_x, source_y, source_size_x, source_size_y, destination_x, destination_y, destination_size_x, destination_size_y</td></tr>";
echo "</table>";
header( "Content-Type: text/html" );
break;
case "display":
ImageJPEG( $theimage );
break;
case "resize":
{
$changed = true;
if (isset($destination_size_x)) {
check to see if value given in percentage or not
if (!strrpos($destination_size_x,"%") === false) {
Percentage given, use that
$destination_size_x = round(ImageSX($theimage) * ( $destination_size_x / 100 ));
}
} else {
$changed = false;
no size_x given, so use image's size
$destination_size_x = ImageSX($theimage);
}
if (isset($destination_size_y)) {
# check to see if value given in percentage or not
if (!strrpos($destination_size_y,'%') === false) {
# Percentage given, use that
$destination_size_y = round(ImageSY($theimage) * ( $destination_size_y / 100 ));
}
} else {
# check if we should just switch to display mode
if ($changed == false) {
ImageJPEG( $theimage );
exit;
}
# no size_y given, so use image's size
$destination_size_y = ImageSY($theimage);
}
}
$newimage = ImageCreate($destination_size_x, $destination_size_y);
ImageCopyResized($newimage, $theimage,0,0,0,0,$destination_size_x,$destination_size_y,ImageSX($theimage),ImageSY($theimage));
ImageJPEG( $newimage );
header( "Content-type: image/jpeg" );
break;
case zoom:
not yet implemented
break;
} # switch
?>