Im doing some work for some people who have hosted web space. They want a the ability to resize jpegs, but unfortunatly their host doesn't support GD or Imagemagick.
I used imglib in a similar stituation, heres an index for finding appropriate files and imglib.php (note copyrights etc ), monkey as required.
------------------------------------------------------------
index.php
---------
<?
include("imglib.php"
// the page header
include("header.inc"
/////////////////
// config variable
$col = 4; // number of column
$maxrow = 4; // max row for table
$dir = "./images"; // the directory where your images are
////////////////////////
// open the directory
$dh = opendir($dir);
$i=0;
while($file = readdir($dh))
{
if( (substr($file,-3)=="gif" || (substr($file,-3)=="jpg" )
{
// insert all images in array
$a_img[] = $file;
$i++;
}
}
$totimg = $i; // total images number
$totxpage = $col*$maxrow; // images x page
$totpages = ($totimg%$totxpage==0)?((int)$totimg/$totxpage)(int)($totimg/$totxpage)+1); // number of total pages
//////////////////////////////////////////////////////////////////
//
// Start to print and page break
//
//////////////////////////////////////////////////////////////////
// your footer page
include("footer.inc"
?>
------------------------------------------------------------
imglib.php
----------
<?
// IMAGE LIBRARY 1.0 FOR PHP WITHOUT USING GDI
// THIS SCRIPT IS MADE BY SLIM WEB ARCHITECTURE
//
// This script is made with help from a perl based script of origin unknown
// It is intended for those whose webhost does not have the GD library installed
// If anyone knows how to read and or write JPG, GIF or PNG feel free to add it to this script
// The nice thing about PHP is its possiblities. The bad thing is that virtually no provider has its full capabilities installed
function getimgwidth($filename) {
global $imgw,$imgh;
$ext=strtoupper(substr($filename,-3));
switch ($ext) {
case "GIF":readgif($filename);return $imgw;break;
case "PNG":readpng($filename);return $imgw;break;
case "JPG":readjpg($filename);return $imgw;break;
case "PEG":readjpg($filename);return $imgw;break;
default: return "0";
}
}
function getimgheight($filename) {
global $imgw,$imgh;
$ext=strtoupper(substr($filename,-3));
switch ($ext) {
case "GIF":readgif($filename);return $imgh;break;
case "PNG":readpng($filename);return $imgh;break;
case "JPG":readjpg($filename);return $imgh;break;
case "PEG":readjpg($filename);return $imgh;break;
default: return "0";
}
}
function readjpg($imgfn) {
global $imgw,$imgh;
$M_SOF0 = chr(192);
$M_SOF15 = chr(207);
$M_SOI = chr(216);
$M_EOI = chr(217);
$M_SOS = chr(218);
$M_COM = chr(254);
$MARKER = chr(255);
$imgfd = fopen ($imgfn, "r"
$imgheader=fread ($imgfd, 2);
if ($imgheader[0]!=$MARKER || $imgheader[1]!=$M_SOI) {
fclose($imgfd);
// die("not a JPG file"
return "0";
}
while (1) {
$db=0;
$c1=fread ($imgfd, 1);
while ($c1 != $MARKER) {
$db++;
$c1 = fread ($imgfd, 1);
}
while ($c1 == $MARKER) {
$c1 = fread ($imgfd, 1);
}
// if ($db) {
// echo "Warning: garbage data found in JPG file \"$imgfn\"\n";
// }
if ($c1 >= $M_SOF0 && $c1 <= $M_SOF15) {
// Do we have width and height?
$imgheader = unpack("nl/Cd/nh/nw", fread ($imgfd, 7));
$l = $imgheader["l"];
$d = $imgheader["d"];
$imgh = $imgheader["h"];
$imgw = $imgheader["w"];
fclose($imgfd);
return "width=$imgw height=$imgh";
} elseif ($c1 == $M_SOS || $c1 == $M_EOI) {
// Did we reach header end?
fclose($imgfd);
// die("endoffile"
return "0";
} else {
// Otherwise, skip this variable
$junk=unpack("ndummy", fread ($imgfd, 2));
$l = ushort($junk["dummy"]) - 2;
if ($l < 0) {
fclose($imgfd);
// die("errormarker"
return "0";
}
fread ($imgfd, $l);
}
}
}
function readgif($imgfn) {
global $imgw,$imgh;
$imgfd = fopen ($imgfn, "r"
$imgheader=fread ($imgfd, 6);
if ($imgheader != "GIF87a" && $imgheader != "GIF89a" {
fclose($imgfd);
// die("$imgfn is not a GIF file"
return "0";
}
// Examine the Logical Screen Descriptor
// my($lsw, $lsh, $pf, $bg, $par) = unpack("vvCCC", read_n_bytes(7));
$imgheader = unpack("vnul/veen/Ctwee/Cdrie/Cvier", fread ($imgfd, 7));
$pf = $imgheader["twee"];
// Is it followed by a Global Color table?
if ($pf & 128) {
// Skip the Global Color Table
$GCTsize = $pf & 7;
fread ($imgfd, 3 * (2 << $GCTsize));
}
// Go through the markers in the header. Stop when height and width are
// determined or when end of header is reached
while (1) {
// Get the next marker
$c = fread ($imgfd, 1);
if ($c == chr(33)) {
// This is an Extension.
// Read the label.
$c = fread ($imgfd, 1);
// Read the remainder of this Extension Block and while we're at it,
// read all possible Data Sub-blocks as well.
while ($blksize = ord(fread ($imgfd, 1))) {
fread ($imgfd, $blksize);
}
} elseif ($c == chr(44)) {
// This is the most holy of all... The Image Descriptor.
$nheader=unpack("vnul/veen/vtwee/vdrie/Cvier", fread ($imgfd, 9));
$imgw=ushort($nheader["twee"]);
$imgh=ushort($nheader["drie"]);
fclose($imgfd);
return "width=$imgw height=$imgh";
} else {
fclose($imgfd);
return "nothing";
}
}
}
function ushort($n) {
if ($n < 0) {$n += 65536;}
return $n;
}
?>
______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.