Jump to content

Problem with creating Thumbnail Images using php.


sandhya

Recommended Posts

Hi all,

    I'm trying to create thumbnails of images from database. for this i'm using the following code.I used the same code some where else. It worked. But not here. What's the problem? Here is the code.

<?

$thumb_dir = "admin/gallery/thumbs/";

$filename = 'admin/gallery/'.$rowgal[gal_photo];

$filename1 = 'admin/gallery/thumbs/'.$rowgal[gal_photo];

$thumb_height = 150;

 

// Content type

header('(anti-spam-(anti-spam-content-type:)) image/jpeg');

 

// Get new sizes

list($width, $height) = getimagesize($filename);

$ratio = ($height/$width);

$newheight = $thumb_height;

$newwidth = round($thumb_height/$ratio);

// Load

$thumb = imagecreatetruecolor($newwidth, $newheight);

$source = imagecreatefromjpeg($filename);

// Resize

imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

 

// Output

//imagejpeg($thumb, $thumb_dir, 100);

imagejpeg($thumb, $filename1, 100);

  ?>

I hope somebody can help me. Thanks in advance.

Link to comment
Share on other sites

I resize like this

 

// create thumbnail (150x150)

$file = $_FILES['image_file']['tmp_name'];
list($width, $height) = getimagesize($file);

if ($width >= $height) {
	// scale to width
	$thumb_width = 150;
	$thumb_height = $height * ($thumb_width / $width);
} else {
	// scale to height
	$thumb_height = 150;
	$thumb_width = $width * ($thumb_height / $height);
}

$image = imagecreatefromjpeg($file);

// create thumbnail file
$thumb_image = imagecreatetruecolor($thumb_width, $thumb_height);
imagecopyresampled($thumb_image, $image, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height);
$output_file = "admin/gallery/thumbs/".$_FILES['image_file']['name'];
imagejpeg($thumb_image, $output_file, 100);

 

hope this helps

Link to comment
Share on other sites

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.