lately ive been building another CMS, and have been touching on various gallery functionality that would be required, i have came up with a problem whilst trying to dynamicalluy generate some thumbnails, what constantly happens is it just outputs alot of junk, you will see this later in the post.
please note i have tried this will both GD1 AND GD2 neither of which work.
(gd1 uses imagecreate() whereas gd2 uses imagecreatetruecolor();)
ok, first heres the function that generates that layout and file information (this is fine, i am only showing it so you know how the source of the layout is generated)
Code: Select all
// display code that the function is called within
// not full code but this is all that should be needed for spotting any errors
function show_files_upload_area ($picture_upload_table, $default_uploaded_directory)
{
$query = "SELECT * FROM $picture_upload_table WHERE allowed = 'n'";
$result = mysql_query($query) or die (mysql_error());
$num_rows = mysql_num_rows($result);
print "<strong>$num_rows</strong> picture(s) currently requiring acceptance<br><br>";
//
if ($num_rows == 1)
{
$array_1 = mysql_fetch_array($result);
// only one thing to display
print "
<form action="picture_admin_uploader_acceptance.php" method="post" enctype="application/x-www-form-urlencoded" name="$array_1[id] target="_self">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class = "picture-details-table-picture-holder" width="17%" rowspan="6">";
// simplify the variable for later passing for functions
$filename = $array_1['url'];
//print "
//<a href="$default_uploaded_directory/$filename" target="_BLANK" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('$filename','','img/avatar_anim.gif',1)">";
thumbnail_generator ($filename, $picture_upload_table, $default_uploaded_directory);
print "</td>";
}Code: Select all
function thumbnail_generator ($filename, $picture_upload_table, $default_uploaded_directory)
{
// we should first open the directory
if (is_dir($default_uploaded_directory))
{
// we are entering a valid directory
// open the directory (DO NOT FORGET TO CLOSE IT)
$directory_handle = chdir($default_uploaded_directory);
if (file_exists($filename))
{
// the file exists
// we are now inside the directory
//define height width of created thumbnail
define('MAX_WIDTH', 100);
define('MAX_HEIGHT', 100);
// lets get extension
$extension = explode(".", $filename);
$ext_count = count($extension);
// we'll need to -1 on this to get true count
$ext_count = ($ext_count - 1);
$file_extension = $extension[$ext_count];
// lower case it
$file_extension = strtolower($file_extension);
// we now have the file extension
// this is can be obtained using $file_extension
// now we should create an if statement based on what sort
// of file we're working with and what method to use
// LATER I WILL BE ADDING SUPPORT FOR OTHER FORMATS
if ($file_extension == "jpg" || $file_extension == "jpeg")
{
// the extension is saying its a jpeg
// lets set a header
// we'll add some error handling here concerning
// the headers already sent error message
if (headers_sent())
{
// headers have already been sent
// ill use output buffering to stop these errors
// as they keep bugging me
// (ob_start(); is called on the actual page and not within the function)
ob_end_flush();
header("Content-type: image/jpeg");
}
else
{
// headers have'nt been sent yet
header("Content-type: image/jpeg");
}
// attempt to open the real full-size file
$filename = imagecreatefromjpeg($filename);
// get the height and width of the original image
$original_height = imagesy($filename);
$original_width = imagesx($filename);
// now we need to get the scale and decide what to do from there
$ratio = min(MAX_WIDTH / $original_width, MAX_HEIGHT / $original_height);
if ($ratio < 1)
{
// the original image needs to be resized
$new_width = floor($scale * $original_width);
$new_height = floor($scale * $original_height);
$temp = imagecreate($new_width, $new_height) or die ("Cannot Create Thumbnail: Possible Problem With Function Coding");
imagecopyresized($temp, $filename, 0, 0, 0, 0, $new_width, $new_height, $original_width, $original_height);
imagedestroy($filename);
$thumbnail = $temp;
if (headers_sent())
{
print "<strong><p>Can't, Headers already sent</p></strong>";
}
else
{
// headers STILL havent been sent
imagejpeg($thumbnail);
}
}
else
{
// the image does'nt need to be resized so we'll just output it
// to the browser straight away
if (headers_sent())
{
print "<strong><p>Can't, Headers already sent</p></strong>";
// ive purposefully not outputted the image, just
// so i can see if its getting to this point in the script
// (outputting as of now, still doesnt work)
}
else
{
// headers STILL havent been sent
$thumbnail = $filename;
imagejpeg($thumbnail);
}
}
}
else
{
print "Not a valid extension";
}
}
else
{
print "file not found in this directory: ";
$current_directory = getcwd();
print "<strong>$current_directory</strong>";
exit;
}
}
else
{
print "Not a valid working directory";
}
// change directory back
chdir("../");
$current_directory = getcwd();
}
heres what it should look like (without thumbnail generation, using hardcoding)

also this might prove useful so ill show it, heres the source code after its all generated
Code: Select all
// Outputted HTML (view source)
<td class = "picture-details-table-picture-holder" width="17%" rowspan="6">ÿØÿà JFIF ÿþ >CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality
ÿÛ C
$.' ",#(7),01444'9=82<.342ÿÛ C
2!!22222222222222222222222222222222222222222222222222ÿÀ
d" ÿÄ
ÿÄ µ } !1AQa"q2