Hi frnds...

here i am getting some error...plz check this one...
these are the two files regarding my code...

thumbnail.php

<?php
class thumbnail {
    var $img;

    function thumbnail($imgfile)
    {
	   
        //detect image format
        $this->img["format"]=ereg_replace(".*\.(.*)$","\\1",$imgfile);
        $this->img["format"]=strtoupper($this->img["format"]);
        if (strtoupper($this->img["format"])=="JPG" || strtoupper($this->img["format"])=="JPEG") {
            //JPEG
            $this->img["format"]="JPEG";
            $this->img["src"] = imagecreatefromjpeg($imgfile);
        
        } elseif ($this->img["format"]=="PNG") {
            //PNG
            $this->img["format"]="PNG";
            $this->img["src"] = @ImageCreateFromPNG ($imgfile);
        } elseif ($this->img["format"]=="GIF") {
            //GIF
            $this->img["format"]="GIF";
            $this->img["src"] = @ImageCreateFromGIF ($imgfile);
        } elseif ($this->img["format"]=="WBMP") {
            //WBMP
            $this->img["format"]="WBMP";
            $this->img["src"] = @ImageCreateFromWBMP ($imgfile);
        } else {
        return 0;
        }
        $this->img["src_width"] = imagesx($this->img["src"]);
        $this->img["src_height"] = imagesy($this->img["src"]);
        
    }
/*$save => containa a path where the thumbnail will be stored ex. sohail/a.png
  $w => width of thumbnail    
  $h => height of thumbnail
*/
    function saveImage($save="",$w,$h)
    {
        
            $old_x=imageSX($save);
            $old_y=imageSY($save);
            if ($old_x > $old_y) {
                $thumb_w=$w;
                $thumb_h=$old_y*($h/$old_x);
            }
            if ($old_x < $old_y) {
                $thumb_w=$old_x*($w/$old_y);
                $thumb_h=$h;
            }
            if ($old_x == $old_y) {
                $thumb_w=$w;
                $thumb_h=$h;
            }
        
        
        $this->img["dest_width"] = $thumb_w ;
        $this->img["dest_height"] = $thumb_h ;
        
        /* change ImageCreateTrueColor to ImageCreate if your GD not supported ImageCreateTrueColor function*/
        $this->img["des"] = imagecreatetruecolor($this->img["dest_width"],$this->img["dest_height"]) ;
       
        @imagecopyresized($this->img["des"], $this->img["src"], 0, 0, 0, 0, $this->img["dest_width"], $this->img["dest_height"], $this->img["src_width"], $this->img["src_height"]);

        if ($this->img["format"]=="JPG" || $this->img["format"]=="JPEG") {
            //JPEG
            

            
            @imagejpeg($this->img["des"],"$save",75);
        } elseif ($this->img["format"]=="PNG") {
            //PNG
            @imagepng($this->img["des"],"$save");
        } elseif ($this->img["format"]=="GIF") {
            //GIF
            @imagegif($this->img["des"],"$save");
        } elseif ($this->img["format"]=="WBMP") {
            //WBMP
            @imagewbmp($this->img["des"],"$save");
        }
    }
}

//End of thumbnail

gallery.php

@$tmp_name0 = $_FILES["attachments4"]["tmp_name"][0];
        @$name0 = $_FILES["attachments4"]["name"][0];
	@$type0=$_FILES["attachments4"]["type"][0];
	 @$size0=$_FILES["attachments4"]["size"][0];

          $title1="../../gallery/allgallerys/$gcategory/$gname";
	
	@move_uploaded_file($tmp_name0, "$title1"."/"."$name0");

if($name0!='')
{	

$thumbpath0="$tpath/thumb/$name0";
$filepath0="$title1/$name0";
$thumb = new thumbnail($filepath0);
[B]$thumb -> saveImage($thumbpath0,"115","120");[/B]
$path="$title"."/"."$name0";
$sql="insert into galleryphotos values('','$gid','$path','$thumbpath0','$date')";
mysql_query($sql)or die(mysql_error());
}

here everything is ok..but my problem is getting warning
and also image is damaged....plz rectify this problem...

$thumb -> saveImage($thumbpath0,"115","120");

If your refering to the above line being the error line then it would be because you need to specify $recourse in the first parameter and not $path. So try looking up functions like createimagefromgif() for the first parameter input. Basically functions like createimagefromjpeg() load a file into the php file system where it can be used via variables.

Hello cwarn,

thanks 4 ur reply..

I dont know exactly where the error occured..

the errors are:

Warning: imagesx(): supplied argument is not a valid Image resource in C:\wamp\www\telugu\admin\gallery\thumbnail.php on line 42

Warning: imagesy(): supplied argument is not a valid Image resource in C:\wamp\www\telugu\admin\gallery\thumbnail.php on line 43

what is meant by $recourse..plz explian this and check the errors which i phased..

$thumb -> saveImage($thumbpath0,"115","120");

If your refering to the above line being the error line then it would be because you need to specify $recourse in the first parameter and not $path. So try looking up functions like createimagefromgif() for the first parameter input. Basically functions like createimagefromjpeg() load a file into the php file system where it can be used via variables.

The error report makes it so much easier. You can ignore most of what I said on my previous post as according to the error message it is the following two lines.

$old_x=imageSX($save);
            $old_y=imageSY($save);

if for example the save image is a jpeg then replace with the following.

$resource=imagecreatefromjpeg($save);
$old_x=imageSX($resource);
            $old_y=imageSY($resource);

Hello sir,

Sorry for not getting again...i done what u said perfectly..but again i am getting an extra error as

Warning: imagecreatefromjpeg(../../gallery/allgallerys/Heroines/Naina/thumb/reema-sen-4-51247033438.jpg) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in C:\wamp\www\telugu\admin\gallery\thumbnail.php on line 41

and also previous errors are repeated..but, the thumbnail is creating. ..but not good clarity..image lokking damaged...

Have you had any experience with PHP files?

What you do is first OPEN the file. This allows PHP to read the contents and attributes it contains.

This is what you must do with your image. You need to use the functions stated above by cwarn23 depending on the file extension.

These will open the files and allow PHP to read information on the specified file. Without this your function will not work as PHP can change the information without knowing everything about this file.

createimagefromjpeg( $path_to_jpeg );

createimagefromgif( $path_to_gif );

createimagefrompng( $path_to_png );

/* I'm not 100% sure but I think there is a createimagefromjpg() function
but don't quote me on it. */
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.