UK WEB HOSTING FORUM FOR DISCUSSION ON WEB HOSTING SERVICE AND SUPPORT
LINUX HOSTING WINDOWS HOSTING PACKAGES SHOPPING CART OSCOMMERCE ZEN CART AGORA
ECOMMERCE HOSTING ASP MSSQL FRONTPAGE HOSTING PHP MYSQL HOSTING DISCUSSION FORUM
CPANEL RESELLER HOSTING DEDICATED SERVER VPS HOSTING PLESK VIRTUOZZO
Quick Search
Your forum announcement here!

  UK Web Hosting | Dedicated Server Windows and Linux VPS Forum > Web Hosting and Domains > PHP Hosting

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 26-10-2007, 17:53
Haz Haz is offline
new member
 
Join Date: Oct 2007
Posts: 3
Default Thumbnailing from php

I am having some trouble creating thumbnails from php.
Using imagecreatefromjpeg(), which I understand uses the GD image library.
Is this included in this build of php.
Is there another way of creating thumbnails dynamically?

This functionality has worked with another host using Cpanel.

Any ideas?
Reply With Quote
  #2 (permalink)  
Old 26-10-2007, 19:11
Premium Member
 
Join Date: Mar 2007
Posts: 417
Default

create a file called test.php or something of your liking. In this file type

HTML Code:
<?php phpinfo(); ?>
then upload it to your server and access it in a web browser. There you can check whether GD2 is enabled.
__________________
http://shubox.net
Reply With Quote
  #3 (permalink)  
Old 30-10-2007, 15:38
Haz Haz is offline
new member
 
Join Date: Oct 2007
Posts: 3
Default Thumbnailing

Yes, GD2 is installed.
Is there any other reason that imagecreatefromjpeg would not work?
Reply With Quote
  #4 (permalink)  
Old 31-10-2007, 13:37
Haz Haz is offline
new member
 
Join Date: Oct 2007
Posts: 3
Default Thumbnailing

The actual error is:
gd-jpeg, libjpeg: recoverable error: Premature end of JPEG file

I have managed to get some files to upload,
however, I have a whole load of jpegs created on a Mac that produce this error.
Any suggestions? other than batch convertion.
It would be nice if this app was solid.
Reply With Quote
  #5 (permalink)  
Old 01-11-2007, 22:29
DavidAllen's Avatar
Premium Member
 
Join Date: Jan 2007
Location: Amersham
Posts: 330
Send a message via MSN to DavidAllen Send a message via Skype™ to DavidAllen
Default Here's mine

Here's the code I use to create thumbnails
Code:
function resizeImage($img, $imgPath, $quality,$medPath,$thumbPath) {
    // Open the original image.
    list($width, $height, $type, $attr) = getimagesize($imgPath.'/'.$img);
    //create new file name
    $baseName = explode("_",$img);
    $newNameE = explode(".", $img);
	
	// thumbnail
	$newName =  $baseName[0] . '.'. $newNameE[1] ;
	//check for existence
	if (!file_exists($thumbPath.$newName)) {
		if (!$original) {
			$original = createimage($imgPath.$img);
		}
	    // Determine new width and height for thumbnail image
	    if ($width>$height) {
	    	$newWidth=72;
	    	$newHeight=72*$height/$width;
	    } else {
			$newHeight=72;
			$newWidth=72*$width/$height;
		}

		// Resample the image.
		$tempImg = imagecreatetruecolor($newWidth, $newHeight);
		if (!$tempImg) {
			return false;
		} else {
		    if (!imagecopyresampled($tempImg, $original, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height)) {
		    	return false;
		    } else {
			    // Save the image.
			    if(!imagejpeg($tempImg, $thumbPath.$newName, $quality)) {
					return false;
				} else {
					//Clean up
				    imagedestroy($original);
				    imagedestroy($tempImg);
				}
			}
		}
	}
    return true;
}
function createimage($pathplusimg) {
    $foriginal = imagecreatefromjpeg($pathplusimg);
    if (!$foriginal) {
    	$foriginal=imagecreatefromgif($pathplusimg);
    }
    if (!$foriginal) {
    	$foriginal=imagecreatefrompng($pathplusimg);
    }
	return $foriginal;
}
key point is probably using
Code:
$tempImg = imagecreatetruecolor($newWidth, $newHeight);
to create a blank image of the new size and then using
Code:
imagecopyresampled($tempImg, $original, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height)
to resize and copy the image
__________________
David Allen - www.serina.co.uk

Last edited by DavidAllen : 01-11-2007 at 22:34. Reason: more detail
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 04:28.

 

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by Web Hosting 3.1.0
Copyright © 2001-2008, eUKhost.com. All rights reserved.

 
Site Map

knowledgebase articles

popular blog categories