$bh ) { $th = ($tw * $bh) / $bw; } else { $tw = ($th * $bw) / $bh; } $timg = imagecreatetruecolor( $tw, $th ); imagecopyresized( $timg, $bimg, 0, 0, 0, 0, $tw, $th, $bw, $bh ); imagedestroy( $bimg ); header( "Expires: Sat, 16 Jan 2038 05:30:00 GMT" ); header( "Content-type: image/jpeg" ); imagejpeg( $timg ); imagedestroy( $timg ); } function gfx_scale( $srcname, $dstname, $angle ) { $dstbasename = substr( $dstname, 0, -4 ); $bigname = $dstbasename . ".jpg"; $scaledname = $dstbasename . ".1024.jpg"; $thumbname = $dstbasename . ".64.jpg"; $thumb2name = $dstbasename . ".128.jpg"; if( $srcname != $bigname ) { if( !rename( $srcname, $bigname ) ) { return false; } if( !rename( $srcname . ".timv", $bigname . ".timv" ) ) { rename( $bigname, $srcname ); return false; } if( !rename( $srcname . ".md5", $bigname . ".md5" ) ) { rename( $bigname, $srcname ); rename( $bigname . ".timv", $srcname . ".timv" ); return false; } } $bimg = imagecreatefromjpeg( $bigname ); if( !$bimg ) { return false; } $bw = imagesx( $bimg ); $bh = imagesy( $bimg ); $sw = 1024; $sh = 1024; $tw = 64; $th = 64; $uw = 128; $uh = 128; if( $bw > $bh ) { $sh = ($sw * $bh) / $bw; $th = ($tw * $bh) / $bw; $uh = ($uw * $bh) / $bw; } else { $sw = ($sh * $bw) / $bh; $tw = ($th * $bw) / $bh; $uw = ($uh * $bw) / $bh; } $simg = imagecreatetruecolor( $sw, $sh ); imagecopyresized( $simg, $bimg, 0, 0, 0, 0, $sw, $sh, $bw, $bh ); imagedestroy( $bimg ); if( $angle != 0 ) { $simg2 = imagerotate( $simg, $angle, 0 ); imagedestroy( $simg ); $simg = $simg2; if( $angle != 180 ) { list( $sw, $sh, $tw, $th, $uw, $uh ) = array( $sh, $sw, $th, $tw, $uh, $uw ); } } $timg = imagecreatetruecolor( $tw, $th ); imagecopyresized( $timg, $simg, 0, 0, 0, 0, $tw, $th, $sw, $sh ); $uimg = imagecreatetruecolor( $uw, $uh ); imagecopyresized( $uimg, $simg, 0, 0, 0, 0, $uw, $uh, $sw, $sh ); $rc = true; if( !imagejpeg( $simg, $scaledname ) ) { $rc = false; } if( !imagejpeg( $timg, $thumbname ) ) { $rc = false; } if( !imagejpeg( $uimg, $thumb2name ) ) { $rc = false; } chown( $scaledname, "www-data" ); chgrp( $scaledname, "www-data" ); chown( $thumbname, "www-data" ); chgrp( $thumbname, "www-data" ); chown( $thumb2name, "www-data" ); chgrp( $thumb2name, "www-data" ); imagedestroy( $simg ); imagedestroy( $timg ); imagedestroy( $uimg ); return $rc; } function str_to_int32( $s ) { return ord(substr($s,0,1)) + ord(substr($s,1,1)) * 0x100 + ord(substr($s,2,1)) * 0x10000 + ord(substr($s,3,1)) * 0x1000000; } function gfx_read_timv( $filename ) { $ifd = fopen( $filename, "rb" ); if( !$ifd ) { echo "error opening '$filename' for reading
\n"; return null; } $data = fread( $ifd, 26 ); fclose( $ifd ); $width = ""; $height = ""; $mtime = ""; $angle = ""; $flip = ""; if( substr( $data, 0, 4 ) == "timv" ) { $width = substr( $data, 8, 4 ); $height = substr( $data, 12, 4 ); // actually 8 bytes $mtime = substr( $data, 16, 4 ); $angle = substr( $data, 24, 1 ); $flip = substr( $data, 25, 1 ); } else { if( ord( substr( $data, 3, 1 ) ) != 0 ) { $data = substr( $data, 4, 14 ); } /* how to get length of a binary string? $l = strlen($data); if( $len < 18 ) { echo "error reading 18 bytes from '$filename'
\n"; return null; } */ $width = substr( $data, 0, 4 ); $height = substr( $data, 4, 4 ); $mtime = substr( $data, 8, 4 ); $angle = substr( $data, 12, 1 ); $flip = substr( $data, 13, 1 ); } $r = array(); /* $r["width"] = ord(substr($wdith,0,1)) + ord(substr($wdith,1,1)) * 0x100 + ord(substr($wdith,2,1)) * 0x10000 + ord(substr($wdith,3,1)) * 0x1000000; $r["height"] = ord(substr($height,4,1)) + ord(substr($height,5,1)) * 0x100 + ord(substr($height,6,1)) * 0x10000 + ord(substr($height,7,1)) * 0x1000000; $r["mtime"] = ord(substr($mtime,8,1)) + ord(substr($mtime,9,1)) * 0x100 + ord(substr($mtime,10,1)) * 0x10000 + ord(substr($mtime,11,1)) * 0x1000000; */ $r["width"] = str_to_int32( $width ); $r["height"] = str_to_int32( $height ); $r["mtime"] = str_to_int32( $mtime ); $r["angle"] = ord($angle); $r["flip"] = ord($flip); /* echo "width='" . $r["width"] . "'\n"; echo "height='" . $r["height"] . "'\n"; echo "mtime='" . $r["mtime"] . "'\n"; echo "angle='" . $r["angle"] . "'\n"; echo "flip='" . $r["flip"] . "'\n"; return null; */ return $r; } function gfx_read_info( $filename ) { $basename = substr( $filename, 0, -4 ); $sfx = substr( $filename, -4 ); if( strcasecmp( $sfx, ".jpg" ) != 0 && strcasecmp( $sfx, ".jpeg" ) != 0 ) { echo "not a jpeg
\n"; return null; } //echo "call my_exif_read_data\n"; $info = my_exif_read_data( $filename ); //echo "done my_exif_read_data\n"; // if( !$info ) if( !isset( $info["Camera"] ) ) { echo "reading exif failed\n"; // return null; $pattern = "/^.*(20[0-9]{2}).([0-9]{2}).([0-9]{2}).([0-9]{2}).([0-9]{2}).([0-9]{2}).*/"; $replace = "\\1 \\2 \\3 \\4 \\5 \\6"; $t = null; $dtstr = preg_replace( $pattern, $replace, $filename ); if( $dtstr != $filename ) { $t = str2time( $dtstr, "%Y %m %d %H %M %S" ); //echo " file date $dtstr\n"; } $info = array( "Camera" => array( "Camera Model" => "unknown" ), "Image" => array(), "CALCULATED" => array( "IMAGEDATE" => $t ) ); } $timv = gfx_read_timv( $filename . ".timv" ); if( !$timv ) { echo "reading timv failed
\n"; return null; } $timv["filename"] = $filename; $timv["basename"] = $basename; $info["timv"] = $timv; return $info; } ?>