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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.