Jump to content

[SOLVED] help needed making this thumbnail creating code work.


Recommended Posts

Hi ,

I got this code from a tutorial.. and it is not working on my php 5 server.

according to me it stops working after this line. ( nothing i echo after it comes on teh screen.)..

 

			      $img = imagecreatefromjpeg( $pathToImages.$philename );
      echo "done so far... ";

i am confused as to what could be the problem. am i using the imagecreatefromjpeg( ); wrongly?

Please Advise...

 

Thanks

 

			////////////////////////////////////////////////////////////////////////////////////////////////
		// ------------------------------------------------------------------------------------------------------------------------------
		function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth, $philename )
		{
		  // open the directory
		//  $dir = opendir( $pathToImages );

		  // loop through it, looking for any/all JPG files:
		//  while (false !== ($fname = readdir( $dir ))) {
		    // parse path for the extension
		//    $info = pathinfo($pathToImages . $fname);
		    // continue only if this is a JPEG image
		//    if ( strtolower($info['extension']) == 'jpg' )
		//    {
		      echo "Creating thumbnail for ".$philename." <br />";
			  echo "pathToImages:".$pathToImages."\n<br>";
			  echo "path = "."".$pathToImages.$philename.""."\n <br>";
		      // load image and get image size
		      $img = imagecreatefromjpeg( $pathToImages.$philename );
                              echo "done so far... ";
		      $width = imagesx( $img );
		      $height = imagesy( $img );
			  echo "width:".$width." height:".$height."\n <br>";

		      // calculate thumbnail size
		      $new_width = $thumbWidth;
		      $new_height = floor( $height * ( $thumbWidth / $width ) );
			  echo "new width:".$new_width." new height:".$new_height."\n <br>";

		      // create a new temporary image
		      $tmp_img = imagecreatetruecolor( $new_width, $new_height );

		      // copy and resize old image into new image
		      imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );

		      // save thumbnail into a file
		      imagejpeg( $tmp_img, "".$pathToThumbs.$philename."" );
		//    }
		//  }
		  // close the directory
		//  closedir( $dir );
		}
		$phath = "images/gallery_pics/".$album_id ."/";
		$phathT= "images/gallery_pics/".$album_id ."/t/";
		// call createThumb function and pass to it as parameters the path
		// to the directory that contains images, the path to the directory
		// in which thumbnails will be placed and the thumbnail's width.
		// We are assuming that the path will be a relative path working
		// both in the filesystem, and through the web for links
		createThumbs($phath,$phathT,100,$filename);
		// ------------------------------------------------------------------------------------------------------------------------------
		///////////////////////////////////////////////////////////////////////////////////////

is GD support compiled into your PHP installation? check phpinfo() to find out.

 

also, if GD support is not compiled in, PHP should complain about an undefined function. If that's the error and you're not seeing it, you should be. Your errors may be turned completely off in php.ini.

is GD support compiled into your PHP installation? check phpinfo() to find out.

 

also, if GD support is not compiled in, PHP should complain about an undefined function. If that's the error and you're not seeing it, you should be. Your errors may be turned completely off in php.ini.

YEs you were right. i switched on the errors and i got this:

 

"Fatal error: Call to undefined function imagecreatefromjpeg() in D:\www\ankur\upload2existingalbum.php on line 47"

 

how do i install GD support to my PHP installation?

Sorry, I don't know anything about compiling PHP on Windows. Linux is pretty straightforward via command line or especially easy via WHM/CPanel. For OS X there's MAMP where everything is precompiled and almost too simple, if that's possible...

Assuming you have the entire (well... standard) php stuff, you should just have to uncomment a line in php.ini.

 

;extension=php_gd2.dll

 

extension=php_gd2.dll

 

 

You have to have php_gd2.dll in your extensions directory though ;p (or your path setting).

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.