Warning: imagecreate() [function.imagecreate]: Invalid image dimensions in /WebAdresaIdeOvde/class_resize.php on line 61
Warning: imagecopyresized(): supplied argument is not a valid Image resource in /WebAdresaIdeOvde/class_resize.php on line 62
Ova skripta ce sigurno nekom koristiti, pa bih vas molio za pomoc da resim ovaj problem. Inace nakacio sam sliku .jpg formata posto samo taj i podrzava dimenzija tipa 300x230pix
class_resize.php
<?
class resize
{
var $iOrig = array(); // uploaded image
var $iNew = object; // image created object
// Contructor resize( ARRAY postimage [, INT mawWidth, INT maxHeight])
// Resize the uploaded image and sets width and/or height to the maximum
// value, keeping the aspect ratio
// ie resise( var, 100, 50 ) an image that size is 200x50 will return an image of 100x25
function resize( $postImage, $maxWidth = 10000, $maxHeight = 10000 )
{
global $_FILES;
$this -> iOrig = $_FILES[ $postImage ];
$this -> type = $this -> imageType( );
$picInfos = getimagesize( $this -> iOrig[ 'tmp_name' ] );
$width = $picInfos[0];
$height = $picInfos[1];
if( $width > $maxWidth & $height <= $maxHeight )
{
$ratio = $maxWidth / $width;
}
elseif( $height > $maxHeight & $width <= $maxWidth )
{
$ratio = $maxHeight / $height;
}
elseif( $width > $maxWidth & $height > $maxHeight )
{
$ratio1 = $maxWidth / $width;
$ratio2 = $maxHeight / $height;
$ratio = ($ratio1 < $ratio2)? $ratio1:$ratio2;
}
else
{
$ratio = 1;
}
$nWidth = floor($width*$ratio);
$nHeight = floor($height*$ratio);
if( $this -> type == 'JPG' )
$origPic = imagecreatefromjpeg( $this -> iOrig[ 'tmp_name' ] );
elseif( $this -> type == 'PNG' )
$origPic = imagecreatefromjpeg( $this -> iOrig[ 'tmp_name' ] );
$this -> iNew = ImageCreate($nWidth,$nHeight);
ImageCopyResized($this -> iNew, $origPic, 0, 0, 0, 0, $nWidth, $nHeight, $width, $height);
}
// function imageType(); return JPG/PNG (so cool !)
function imageType( )
{
if( eregi( "jpeg", $this -> iOrig[ 'type' ]) ) // JPG
return "JPG";
elseif( eregi( "png", $this -> iOrig[ 'type' ] ) ) // PNG
return "PNG";
}
// function saveTo( STRING name [, STRING path ] )
// save the new image in the specified path, with the specified name
function saveTo( $name = '', $path = "./" )
{
if( empty( $name ) )
echo "name!";
elseif( !is_dir( $path ) )
echo "$path is not a directory!";
else
{
if( $this -> type == 'JPG' )
imagejpeg( $this -> iNew, $path.$name );
elseif( $this -> type == 'PNG' )
imagepng( $this -> iNew, $path.$name );
}
}
}
?>
Receipt.php
<?
require( 'class_resize.php' );
// resize $_FILES[ 'myUploadedFile' ] widht
// evo napravio sam izmenu kao sto je "mVeliki" rekao i sada radi resize
$thumbail = new resize( 'myUploadedFile', 400, 300 );
// save the resized image to "./TEMP.EXT"
$thumbail -> saveTo( "TEMP.".$thumbail -> type );
?>
Form.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Upload file</title>
</head>
<body>
<form action=receipt.php method=post enctype="multipart/form-data">
<small>File to resize (JPEG or PNG files only)</small><br>
<input type=file name=myUploadedFile><br>
<input type=submit value=Resize>
</form>
</body>
</html>
[Ovu poruku je menjao zrnoo dana 30.06.2007. u 16:23 GMT+1]