corillo181 Posted July 10, 2006 Share Posted July 10, 2006 before my question, nice changes to this site looking great!!!..nowi have no idea how to deal with thumbnails.. i have seen a lot of tutorials but is like none of them make sense at all..is there any place where i can find a nice detialed tutorial on how to make thumbnails of pictures that are already in a directory..or when they are been uploaded to the site.. and how to out put them becuase i t ried to use the code in the same page and it show all the page source code..??? :-[ Link to comment https://forums.phpfreaks.com/topic/14158-thumbnails/ Share on other sites More sharing options...
corillo181 Posted July 10, 2006 Author Share Posted July 10, 2006 :S no one? Link to comment https://forums.phpfreaks.com/topic/14158-thumbnails/#findComment-55713 Share on other sites More sharing options...
hey_im_chris Posted July 10, 2006 Share Posted July 10, 2006 I'm interested in this, too. I don't care for fancy scripts that do a whole bunch of other stuff I don't need, just a nice little script that makes thumbs of the files in a particular directory plus easy to edit settings like thumbnail size, style and number of thumbnails per line. :D Link to comment https://forums.phpfreaks.com/topic/14158-thumbnails/#findComment-55832 Share on other sites More sharing options...
redarrow Posted July 10, 2006 Share Posted July 10, 2006 <?php/* Tye Shavik (tye at tye . ca)*/function create_thumbnail($infile,$outfile,$maxw,$maxh,$stretch = FALSE) { clearstatcache(); if (!is_file($infile)) { trigger_error("Cannot open file: $infile",E_USER_WARNING); return FALSE; } if (is_file($outfile)) { trigger_error("Output file already exists: $outfile",E_USER_WARNING); return FALSE; } $functions = array( 'image/png' => 'ImageCreateFromPng', 'image/jpeg' => 'ImageCreateFromJpeg', ); // Add GIF support if GD was compiled with it if (function_exists('ImageCreateFromGif')) { $functions['image/gif'] = 'ImageCreateFromGif'; } $size = getimagesize($infile); // Check if mime type is listed above if (!$function = $functions[$size['mime']]) { trigger_error("MIME Type unsupported: {$size['mime']}",E_USER_WARNING); return FALSE; } // Open source image if (!$source_img = $function($infile)) { trigger_error("Unable to open source file: $infile",E_USER_WARNING); return FALSE; } $save_function = "image" . strtolower(substr(strrchr($size['mime'],'/'),1)); // Scale dimensions list($neww,$newh) = scale_dimensions($size[0],$size[1],$maxw,$maxh,$stretch); if ($size['mime'] == 'image/png') { // Check if this PNG image is indexed $temp_img = imagecreatefrompng($infile); if (imagecolorstotal($temp_img) != 0) { // This is an indexed PNG $indexed_png = TRUE; } else { $indexed_png = FALSE; } imagedestroy($temp_img); } // Create new image resource if ($size['mime'] == 'image/gif' || ($size['mime'] == 'image/png' && $indexed_png)) { // Create indexed $new_img = imagecreate($neww,$newh); // Copy the palette imagepalettecopy($new_img,$source_img); $color_transparent = imagecolortransparent($source_img); if ($color_transparent >= 0) { // Copy transparency imagefill($new_img,0,0,$color_transparent); imagecolortransparent($new_img, $color_transparent); } } else { $new_img = imagecreatetruecolor($neww,$newh); } // Copy and resize image imagecopyresampled($new_img,$source_img,0,0,0,0,$neww,$newh,$size[0],$size[1]); // Save output file if ($save_function == 'imagejpeg') { // Change the JPEG quality here if (!$save_function($new_img,$outfile,75)) { trigger_error("Unable to save output image",E_USER_WARNING); return FALSE; } } else { if (!$save_function($new_img,$outfile)) { trigger_error("Unable to save output image",E_USER_WARNING); return FALSE; } } // Cleanup imagedestroy($source_img); imagedestroy($new_img); return TRUE;}// Scales dimensionsfunction scale_dimensions($w,$h,$maxw,$maxh,$stretch = FALSE) { if (!$maxw && $maxh) { // Width is unlimited, scale by width $newh = $maxh; if ($h < $maxh && !$stretch) { $newh = $h; } else { $newh = $maxh; } $neww = ($w * $newh / $h); } elseif (!$maxh && $maxw) { // Scale by height if ($w < $maxw && !$stretch) { $neww = $w; } else { $neww = $maxw; } $newh = ($h * $neww / $w); } elseif (!$maxw && !$maxh) { return array($w,$h); } else { if ($w / $maxw > $h / $maxh) { // Scale by height if ($w < $maxw && !$stretch) { $neww = $w; } else { $neww = $maxw; } $newh = ($h * $neww / $w); } elseif ($w / $maxw <= $h / $maxh) { // Scale by width if ($h < $maxh && !$stretch) { $newh = $h; } else { $newh = $maxh; } $neww = ($w * $newh / $h); } } return array(round($neww),round($newh));}?> Link to comment https://forums.phpfreaks.com/topic/14158-thumbnails/#findComment-55849 Share on other sites More sharing options...
hey_im_chris Posted July 10, 2006 Share Posted July 10, 2006 Thanks redarrow! How am I suppossed to handle this? I tried the obvious, 'save as index.php and upload it into the images directory' but that returned nothing. Could you explain to me what I/we're suppossed to do? Hehe :) Link to comment https://forums.phpfreaks.com/topic/14158-thumbnails/#findComment-55861 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.