phpbar.de logo

Mailinglisten-Archive

[php] R: [php] jpeg/gif dateien resizen

[php] R: [php] jpeg/gif dateien resizen

PPK Screen ppk_(at)_datacomm.ch
Thu, 17 Feb 2000 11:03:15 +0100


This is a multi-part message in MIME format.

------=_NextPart_000_0000_01BF7936.96BC9740
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 8bit

Als anlage ein uebersicht fuer bilder voranschau

Saluti

Patrik



-----Messaggio originale-----
Da: php-admin_(at)_infosoc.uni-koeln.de
[mailto:php-admin_(at)_infosoc.uni-koeln.de]Per conto di Michael Renner
Inviato: giovedì 17 febbraio 2000 8.28
A: php_(at)_solix.wiso.Uni-Koeln.DE
Oggetto: Re: [php] jpeg/gif dateien resizen


On Wed, 16 Feb 2000, Matthias H. Risse wrote:
>
> hallo,
>
> ich suche eine einfach möglichkeit thumb-nails
> von jpg und gif bildern auf meinen server zu erzeugen.
>
> geht das über eine bestimmte php-function oder lib
> oder muß ich da ein schon kompiliertes programm
> per shell-command [ exec() ] machen?
>
> danke, würde ich über tips freuen. konnte
> diesbezüglich in den faqs nichts finden und hoffe
> niemanden mit so einer pissel-frage zu nerven :)

Moin,
mache es über einen externen Befehl:

$browser_ext=jpeg;
passthru("/usr/X11R6/bin/mogrify -format $browser_ext -geometry 30% $wfile
2>/dev/stdout ");
# Das wandlet die Datei $wfile auf 30% der Grösse, ausserdem
# nach jpeg.

# Jetzt diese Datei öffenen und dem Browser liefern!
# Wie ist wohl der Dateiname?
        $filename_new=substr($wfile,0,-4);
        $filename_new = "$filename_new.$browser_ext";
	$rfile = "$filename_new";
        $rf = fopen("$rfile", "r");
        $browser_image = fread($rf, filesize( $rfile ));
        echo $browser_image;
# Die Dateien löschen, keinen Schrott auf der Platte lassen
        unlink($rfile);
	unlink($wfile);


Ich gestehe, die Dateinamenswandlung ist etwas abenteuerlich,
aber es funktioniert.
CU
--
+---------------------------------------------------------+
|Michael Renner                   |                       |
|MPI fuer biologische Kybernetik  |Phone: +49-7071-601-638|
|Spemannstr.38, D-72076 Tuebingen |FAX:   +49-7071-601-616|
|michael.renner_(at)_tuebingen.mpg.de  |                       |
+----------------------------------------------------ESC:wq






--
** Durchgehend geöffnet: http://www.php-center.de **
Die PHP-Liste: mailto:php_(at)_infosoc.uni-koeln.de
http://infosoc.uni-koeln.de/mailman/listinfo/php

------=_NextPart_000_0000_01BF7936.96BC9740
Content-Type: application/octet-stream;
	name="class.File.php3"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="class.File.php3"

<?
/*

	File 1.0 - A wrapper class to common PHP file operations
	Copyright (c) 1999 CDI, cdi_(at)_thewebmasters.net
	All Rights Reserved

*/

Class File
{
	var $ERROR =3D "";
	var $BUFFER =3D -1;
	var $STATCACHE =3D array();
	var $TEMPDIR =3D '/tmp';
	var $REALUID =3D -1;
	var $REALGID =3D -1;

	function File ()
	{
		global $php_errormsg;
		return;
	}

	function clear_cache()
	{
		unset($this->STATCACHE);
		$this->STATCACHE =3D array();
		return true;
	}

	function is_sane($fileName =3D "", $must_exist =3D 0, $noSymLinks =3D =
0, $noDirs =3D 0)
	{
		$exists =3D false;

		if(empty($fileName)) {	return false; }
		if($must_exist !=3D 0)
		{
			if(!file_exists($fileName))
			{
				$this->ERROR =3D "is_sane: [$fileName] does not exist";
				return false;
			}
			$exists =3D true;
		}
		if($exists)
		{
			if(!is_readable($fileName))
			{
				$this->ERROR =3D "is_sane: [$fileName] not readable";
				return false;
			}

			if($noDirs !=3D 0)
			{
				if(is_dir($fileName))
				{
					$this->ERROR =3D "is_sane: [$fileName] is a directory";
					return false;
				}
			}

			if($noSymLinks !=3D 0)
			{
				if(is_link($fileName))
				{
					$this->ERROR =3D "is_sane: [$fileName] is a symlink";
					return false;
				}
			}

		} // end if exists

		return true;	=09
	}


//	**************************************************************

	function read_file ($fileName =3D "" )
	{
		$contents =3D "";

		if(empty($fileName))
		{
			$this->ERROR =3D "read_file: No file specified";=20
			return false;
		}
		if(!$this->is_sane($fileName,1,0,1))
		{
			// Preserve the is_sane() error msg
			return false;
		}
		$fd =3D _(at)_fopen($fileName,"r");

		if( (!$fd) || (empty($fd)) )
		{
			$this->ERROR =3D "read_file: File error: [$php_errormsg]";
			return false;
		}

		$contents =3D fread($fd, filesize($fileName) );

		fclose($fd);

        return $contents;
	}

//	**************************************************************
//	Read a file via fgetss(), which strips all php/html
//	from the file.

	function strip_read ($fileName =3D "", $strip_cr =3D 0)
	{
		if(empty($fileName))
		{
			$this->ERROR =3D "strip_read: No file specified";=20
			return false;
		}
		if(!$this->is_sane($fileName,1,0,1))
		{
			// Preserve the error
			return false;
		}
		if($this->BUFFER > 0)
		{
			$buffer =3D $this->BUFFER;
		} else {
			$buffer =3D filesize($fileName);
		}

		$contents =3D "";

		$fd =3D _(at)_fopen($fileName,"r");

		if( (!$fd) || (empty($fd)) )
		{
			$this->ERROR =3D "strip_read: File error: [$php_errormsg]";
			return false;
		}
		while(!feof($fd))
		{
			$contents .=3D fgetss($fd,$buffer);
		}
		fclose($fd);
        return $contents;
	}

//	**************************************************************
	function write_file ($fileName,$Data)
	{
		$tempDir =3D $this->TEMPDIR;
		$tempfile   =3D tempnam( $tempDir, "cdi" );

		if(!$this->is_sane($fileName,0,1,1))
		{
			return false;
		}

		if (file_exists($fileName))
		{
			if (!copy($fileName, $tempfile))
			{
				$this->ERROR =3D "write_file: cannot create backup file [$tempfile] =
:  [$php_errormsg]";
				return false;
			}
		}

		$fd =3D _(at)_fopen( $tempfile, "a" );

		if( (!$fd) or (empty($fd)) )
		{
			$myerror =3D $php_errormsg;
			unlink($tempfile);
			$this->ERROR =3D "write_file: [$tempfile] access error [$myerror]";
			return false;
		}

		fwrite($fd, $Data);

		fclose($fd);

		if (!copy($tempfile, $fileName))
		{
			$myerror =3D $php_errormsg;   // Stash the error, see above
			unlink($tempfile);
			$this->ERROR =3D "write_file: Cannot copy file [$fileName] =
[$myerror]";
			return false;
		}

		unlink($tempfile);

		if(file_exists($tempfile))
		{
			// Not fatal but it should be noted
			$this->ERROR =3D "write_file: Could not unlink [$tempfile] : =
[$php_errormsg]";
		}
		return true;
	}

//	**************************************************************
	function copy_file ($oldFile =3D "", $newFile =3D "")
	{
		if(empty($oldFile))
		{
			$this->ERROR =3D "copy_file: oldFile not specified";
			return false;
		}
		if(empty($newFile))
		{
			$this->ERROR =3D "copy_file: newFile not specified";
			return false;
		}
		if(!$this->is_sane($oldFile,1,0,1))
		{
			// preserve the error
			return false;
		}
		if(!$this->is_sane($newFile,0,1,1))
		{
			// preserve it
			return false;
		}

		if (! (_(at)_copy($oldFile, $newFile)))
		{
			$this->ERROR =3D "copy_file: cannot copy file [$oldFile] =
[$php_errormsg]";
			return false;
		}

		return true;
	}

//	**********************************************

	function get_files ($root_dir, $fileExt =3D 'ALL_FILES')
	{
		$fileList =3D array();

		if(!is_dir($root_dir))
		{
			$this->ERROR =3D "get_files: Sorry, [$root_dir] is not a directory";
			return false;
		}

		if(empty($fileExt))
		{
			$this->ERROR =3D "get_files: No file extensions specified";
			return false;
		}

		$open_dir =3D _(at)_opendir($root_dir);

		if( (!$open_dir) or (empty($open_dir)) )
		{
			$this->ERROR =3D "get_files: Failed to open dir [$root_dir] : =
$php_errormsg";
			return false;
		}

		$fileCount =3D 0;

		while ( $file =3D readdir($open_dir))
		{
			if( (!is_dir($file)) and (!empty($file)) )
			{
				if($fileExt =3D=3D 'ALL_FILES')
				{
					$fileList[$fileCount] =3D $file;
					$fileCount++;
				}
				else
				{
					if(eregi(".\.($fileExt)$",$file))
					{
						$fileList[$fileCount] =3D $file;
						$fileCount++;
					}
				}
			}
		}

		closedir($open_dir);
		return $fileList;

	}	// end get_files

	function is_owner($fileName, $uid =3D "")
	{
		if(empty($uid))
		{
			if($this->REALUID < 0)
			{
				$tempDir =3D $this->TEMPDIR;
				$tempFile =3D tempnam($tempDir,"cdi");
				if(!touch($tempFile))
				{
					$this->ERROR =3D "is_owner: Unable to create [$tempFile]";
					return false;
				}
				$stats =3D stat($tempFile);
				unlink($tempFile);
				$uid =3D $stats[4];
			}
			else
			{
				$uid =3D $this->REALUID;
			}
		}
		$fileStats =3D stat($fileName);
		if( (empty($fileStats)) or (!$fileStats) )
		{
			$this->ERROR =3D "is_owner: Unable to stat [$fileName]";
			return false;
		}

		$this->STATCACHE =3D $fileStats;

		$owner =3D $fileStats[4];
		if($owner =3D=3D $uid)
		{
			return true;
		}

		$this->ERROR =3D "is_owner: Owner [$owner] Uid [$uid] FAILED";
		return false;
	}

	function is_inGroup($fileName, $gid =3D "")
	{
		if(empty($gid))
		{
			if($this->REALGID < 0)
			{
				$tempDir =3D $this->TEMPDIR;
				$tempFile =3D tempnam($tempDir,"cdi");
				if(!touch($tempFile))
				{
					$this->ERROR =3D "is_inGroup: Unable to create [$tempFile]";
					return false;
				}
				$stats =3D stat($tempFile);
				unlink($tempFile);
				$gid =3D $stats[5];
			}
			else
			{
				$gid =3D $this->REALGID;
			}
		}
		$fileStats =3D stat($fileName);
		if( (empty($fileStats)) or (!$fileStats) )
		{
			$this->ERROR =3D "is_inGroup: Unable to stat [$fileName]";
			return false;
		}

		$this->STATCACHE =3D $fileStats;

		$group =3D $fileStats[5];
		if($group =3D=3D $gid)
		{
			return true;
		}

		$this->ERROR =3D "is_inGroup: Group [$group] Gid [$gid] FAILED";
		return false;
	}

	function get_real_uid()
	{
		$tempDir =3D $this->TEMPDIR;
		$tempFile =3D tempnam($tempDir,"cdi");
		if(!touch($tempFile))
		{
			$this->ERROR =3D "is_owner: Unable to create [$tempFile]";
			return false;
		}
		$stats =3D stat($tempFile);
		unlink($tempFile);
		$uid =3D $stats[4];
		$gid =3D $stats[5];
		$this->REALUID =3D $uid;
		$this->REALGID =3D $gid;
		return $uid;
	}

	function get_real_gid()
	{
		$uid =3D $this->get_real_uid();
		if( (!$uid) or (empty($uid)) )
		{
			return false;
		}
		return $this->REALGID;
	}

}	// end class File

?>
------=_NextPart_000_0000_01BF7936.96BC9740
Content-Type: application/octet-stream;
	name="index.php3"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="index.php3"

<?php=20


include( "class.File.php3");=20

// RELATIVE PATH TO IMAGES DIRECTORY (Other than gallery.php3's)=20
$path =3D  ".";=20

// NUMBER OF COLUMNS TO BE DISPLAYED=20
$colunas =3D 6;=20

// THUMBNAIL WIDTH=20
$thumb_width =3D  "100";=20

// THUMBNAIL HEIGHT=20
$thumb_height =3D  "";=20

/* COORDINATES FOR THE FULL SIZE PHOTO POP-UP WINDOW =20
YOU CAN USE (MINUS) TO INVERT THE REFERENCES =20
(RIGHTMARGIN AND BOTTOMMARGIN). PREETY COOL, ISN'T IT? */=20

// LEFTMARGIN OFFSET (RIGTHMARGIN IF YOU USE NEGATIVE VALUES)=20
$pop_leftmargin =3D  "1";=20

// TOPMARGIN OFFSET (BOTTOMMARGIN IF YOU USE NEGATIVE VALUES)=20
$pop_topmargin =3D  "1";=20

//***********************************************************//=20
//******** ENDOF VARIABLES CONFIGURATION SECTION ************//=20
//***********************************************************//=20

$file =3D new File(); =20
$images =3D array();=20
$jpgs =3D $file->get_files( "$path", "jpg");=20
if( !empty($jpgs) ) {=20
    while ( list( $key, $filename ) =3D each( $jpgs ) ) {=20
    $images[] =3D $filename;=20
    }=20
}=20
$gifs =3D $file->get_files( "$path", "gif");=20
if( !empty($gifs) ) {=20
    while ( list( $key, $filename ) =3D each( $gifs ) ) {=20
    $images[] =3D $filename;=20
    }=20
}=20
$pngs =3D $file->get_files( "$path", "png");=20
if( !empty($pngs) ) {=20
    while ( list( $key, $filename ) =3D each( $pngs ) ) {=20
    $images[] =3D $filename;=20
    }=20
}=20
$bmps =3D $file->get_files( "$path", "bmp");=20
if( !empty($bmps) ) {=20
    while ( list( $key, $filename ) =3D each( $bmps ) ) {=20
    $images[] =3D $filename;=20
    }=20
}=20
$count =3D 1;=20
$break =3D $colunas;=20
?>=20
<!-- STARTOF HTML CODE - CUSTOMIZE AS YOU WISH -->=20
<!-- JUST DON'T TOUCH THE JAVA CODE -->=20
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">=20
<HTML>=20
<HEAD>=20
    <TITLE>The Jazzascona Performers Photo Gallery</TITLE>=20
<SCRIPT Language=3D"JavaScript"> =20
<!--  =20
var popWin =3D null   =20
var winCount =3D 0=20
var winName =3D "popWin"=20
function openPopWin(winURL, winWidth, winHeight, winFeatures, winLeft, =
winTop){=20
  var d_winLeft =3D 20 =20
  var d_winTop =3D 20  =20
  winName =3D "popWin" + winCount++ =20
  closePopWin()          =20
  if (openPopWin.arguments.length >=3D 4)   =20
    winFeatures =3D "," + winFeatures=20
  else =20
    winFeatures =3D "" =20
  if (openPopWin.arguments.length =3D=3D 6)  =20
    winFeatures +=3D getLocation(winWidth, winHeight, winLeft, winTop)=20
  else=20
    winFeatures +=3D getLocation(winWidth, winHeight, d_winLeft, =
d_winTop)=20
  popWin =3D window.open(winURL, winName, "width=3D" + winWidth =20
           + ",height=3D" + winHeight + winFeatures)=20
  }=20
function closePopWin(){    =20
  if (navigator.appName !=3D "Microsoft Internet Explorer" =20
      || parseInt(navigator.appVersion) >=3D4) =20
    if(popWin !=3D null) if(!popWin.closed) popWin.close() =20
  }=20
function getLocation(winWidth, winHeight, winLeft, winTop){=20
  return ""=20
  }=20
//-->=20
</SCRIPT>=20
<SCRIPT Language=3D"JavaScript1.2">=20
<!--=20
function getLocation(winWidth, winHeight, winLeft, winTop){=20
  var winLocation =3D ""=20
  if (winLeft < 0)=20
    winLeft =3D screen.width - winWidth + winLeft=20
  if (winTop < 0)=20
    winTop =3D screen.height - winHeight + winTop=20
  if (winTop =3D=3D "cen")=20
    winTop =3D (screen.height - winHeight)/2 - 20=20
  if (winLeft =3D=3D "cen")=20
    winLeft =3D (screen.width - winWidth)/2=20
  if (winLeft>0 & winTop>0)=20
    winLocation =3D  ",screenX=3D" + winLeft + ",left=3D" + winLeft    =20
                + ",screenY=3D" + winTop + ",top=3D" + winTop=20
  else=20
    winLocation =3D ""=20
  return winLocation=20
  }=20
//-->=20
</SCRIPT>=20
<style>=20
<!--=20
BODY {=20
        font-family: Verdana,Arial;=20
        font-style: none;=20
        font-size: 16px;=20
}=20
BIG {=20
        font-size: 28px;=20
        font-weight: bold;=20
}=20
TABLE {=20
        font-size: 16px;=20
}=20
SMALL {=20
        font-size: 12px;=20
}=20

A:LINK {=20
        text-decoration: none;=20
        font-weight: bold;=20
}=20
-->=20
</style>    =20
</HEAD>=20
<BODY onUnload=3D"closePopWin()">=20

<div align=3D"CENTER">=20
<b>The Jazzascona Performers Photo Gallery (php Live read Folder)<br>
<a href=3D"http://www.jazzascona.ch">www.jazzascona.ch</a></b><br>=20
<small>PPK ScrenDesign Gordevio</b> &reg; 2000<br>=20
<a href=3D"mailto:info_(at)_ticinonline.to">info_(at)_ticinonline.to</a></small>=20
</div>=20
<div align=3D"center"><b>(Click the thumbnails to enlarge &shy; Total in =
this page: =20
<?php echo count($images); ?> images)</b></small> </div>


<table border=3D"5" cellspacing=3D"0" cellpadding=3D"6">=20
<tr>=20
<!-- STARTOF TABLE CELL DISPLAY PHP CODE -->=20
<!-- DO NOT ALTER IT -->=20
<?php=20
while ( list( $key, $fileName ) =3D each( $images ) )=20
{ =20
    if( !empty($fileName) ) =20
    { =20
    $tamanho =3D GetImageSize( "$fileName");=20
    $largura =3D $tamanho[0] + 18;=20
    $altura =3D $tamanho[1] + 28;=20
    echo  "  <td align=3D\"CENTER\" valign=3D\"TOP\"><a =
href=3D'javascript:openPopWin(\"$fileName\", $largura, $altura, \"\", =
$pop_leftmargin, $pop_topmargin)'><IMG SRC=3D\"$fileName\" border=3D0 =
alt=3D\"$count\"";=20
    if (!empty($thumb_width)) {echo  " width=3D\"$thumb_width\"";}=20
    if (!empty($thumb_height)) {echo  " height=3D\"$thumb_height\"";}=20
    echo  "></a><br><small>$count-$fileName</small>";=20

        if ($count =3D=3D $break) {  =20
            echo  "\n  </td>\n</tr>\n<tr>\n";=20
            $break =3D $count + $colunas; =20
            }=20
        else { echo  "</td>\n"; }=20
    }=20
    $count++;=20
} =20
?>=20
<!-- ENDOF TABLE CELL CODE PHP-->=20
</tr>=20
</table>=20
</div>=20
<hr>=20
<div align=3D"CENTER">=20
<b>The Jazzascona Performers Photo Gallery</b><br>=20
<small>PPK ScrenDesign Gordevio</b> &reg; 2000<br>=20
<a href=3D"mailto:info_(at)_ticinonline.to">info_(at)_ticinonline.to</a></small>=20
</div>=20
</BODY>=20
</HTML>=20

------=_NextPart_000_0000_01BF7936.96BC9740--



php::bar PHP Wiki   -   Listenarchive