Jump to content

cheezylu

Members
  • Posts

    12
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Female
  • Location
    Chicago, IL

cheezylu's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. This may help. Here is a modified code from lixlpixel of PHP Paradise.  This will create a cropped thumbnail of a JPEG and upload them both into a specified directory. [code]<?php if(isset($_POST['Submit'])) { $size = 100; // the thumbnail height $filedir = 'pics/'; // the directory for the original image $thumbdir = 'pics/'; // the directory for the thumbnail image $prefix = 'THUM_'; // the prefix to be added to the original name $maxfile = '2000000'; $mode = '0666'; $userfile_name = $_FILES['image']['name']; $userfile_tmp = $_FILES['image']['tmp_name']; $userfile_size = $_FILES['image']['size']; $userfile_type = $_FILES['image']['type']; if (isset($_FILES['image']['name'])) { $prod_img = $filedir.$userfile_name; $prod_img_thumb = $thumbdir.$prefix.$userfile_name; move_uploaded_file($userfile_tmp, $prod_img); chmod ($prod_img, octdec($mode)); $sizes = getimagesize($prod_img); $aspect_ratio_wide = $sizes[1]/$sizes[0]; $aspect_ratio_tall = $sizes[0]/$sizes[1]; if ($sizes[1] > $sizes[0]) // if height is greater than width { if ($sizes[0] <= $size) // if width <= defined size { $new_width = $sizes[0]; $new_height = $sizes[1]; }else{ $new_width = $size; $new_height = abs($new_width/$aspect_ratio_tall); } $size_difference_height = $sizes[1] / $new_height; $center_width = 0; $center_height = (($new_height - $size) / 2) * $size_difference_height; } else if ($sizes[0] > $sizes[1]) { // else if width is greater than height if ($sizes[1] <= $size) { $new_width = $sizes[0]; $new_height = $sizes[1]; }else{ $new_height = $size; $new_width = abs($new_height/$aspect_ratio_wide); } $size_difference_width = $sizes[0] / $new_width; $center_width = (($new_width - $size) / 2) * $size_difference_width; $center_height = 0; } $destimg = imagecreatetruecolor($size,$size) or die('Problem In Creating image'); $srcimg = imagecreatefromjpeg($prod_img) or die('Problem In opening Source Image'); imagecopyresampled($destimg,$srcimg,0,0,$center_width,$center_height,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die('Problem In resizing'); ImageJPEG($destimg,$prod_img_thumb,90) or die('Problem In saving'); imagedestroy($destimg); } echo ' <a href="'.$prod_img.'"> <img src="'.$prod_img_thumb.'" width="$size" height="$size"> </a> '; }else{ echo ' <form method="POST" action="'.$_SERVER['PHP_SELF'].'" enctype="multipart/form-data"> <input type="file" name="image"><p> <input type="Submit" name="Submit" value="Submit"> </form>'; } ?>[/code]
  2. Woo... I believe I have it figured out! Here is a modified code from lixlpixel of PHP Paradise.  This will create a cropped thumbnail of a JPEG and upload them both into a specified directory. [code]<?php if(isset($_POST['Submit'])) { $size = 100; // the thumbnail height $filedir = 'pics/'; // the directory for the original image $thumbdir = 'pics/'; // the directory for the thumbnail image $prefix = 'THUM_'; // the prefix to be added to the original name $maxfile = '2000000'; $mode = '0666'; $userfile_name = $_FILES['image']['name']; $userfile_tmp = $_FILES['image']['tmp_name']; $userfile_size = $_FILES['image']['size']; $userfile_type = $_FILES['image']['type']; if (isset($_FILES['image']['name'])) { $prod_img = $filedir.$userfile_name; $prod_img_thumb = $thumbdir.$prefix.$userfile_name; move_uploaded_file($userfile_tmp, $prod_img); chmod ($prod_img, octdec($mode)); $sizes = getimagesize($prod_img); $aspect_ratio_wide = $sizes[1]/$sizes[0]; $aspect_ratio_tall = $sizes[0]/$sizes[1]; if ($sizes[1] > $sizes[0]) // if height is greater than width { if ($sizes[0] <= $size) // if width <= defined size { $new_width = $sizes[0]; $new_height = $sizes[1]; }else{ $new_width = $size; $new_height = abs($new_width/$aspect_ratio_tall); } $size_difference_height = $sizes[1] / $new_height; $center_width = 0; $center_height = (($new_height - $size) / 2) * $size_difference_height; } else if ($sizes[0] > $sizes[1]) { // else if width is greater than height if ($sizes[1] <= $size) { $new_width = $sizes[0]; $new_height = $sizes[1]; }else{ $new_height = $size; $new_width = abs($new_height/$aspect_ratio_wide); } $size_difference_width = $sizes[0] / $new_width; $center_width = (($new_width - $size) / 2) * $size_difference_width; $center_height = 0; } $destimg = imagecreatetruecolor($size,$size) or die('Problem In Creating image'); $srcimg = imagecreatefromjpeg($prod_img) or die('Problem In opening Source Image'); imagecopyresampled($destimg,$srcimg,0,0,$center_width,$center_height,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die('Problem In resizing'); ImageJPEG($destimg,$prod_img_thumb,90) or die('Problem In saving'); imagedestroy($destimg); } echo ' <a href="'.$prod_img.'"> <img src="'.$prod_img_thumb.'" width="$size" height="$size"> </a> '; }else{ echo ' <form method="POST" action="'.$_SERVER['PHP_SELF'].'" enctype="multipart/form-data"> <input type="file" name="image"><p> <input type="Submit" name="Submit" value="Submit"> </form>'; } ?>[/code]
  3. I would like to know how to do this too...
  4. I know how to upload images directly into a SQL table, but I was curious if it's possible to automatically create a thumbnail version in the table every time an image is uploaded. I know how to do this if the images are being stored in a directory, but not a SQL database. Is it even possible? I chose to store the images in the database because I am doing a site for a client and I want them to be able to make updates through an admin page I made for them... so they can add, update, and delete the images attached to their journal entries and whatnot without any orphaned images filling up their directories. Is it possible to not orphan files when storing the images in a directory and just have the SQL table point to that file name? (without creating any extra work for my client, of course) Any ideas?
  5. Thanks, I'll try this out. I chose to store the images in the database because I am doing a site for a client and I want them to be able to make updates through an admin page I made for them... so they can add, update, and delete the images attached to their journal entries and whatnot without any orphaned images filling up their directories. Is this still possible to do by storing the images in directories?
  6. I know how to upload images directly into a SQL table, but I was curious if it's possible to automatically create a thumbnail version in the table every time an image is uploaded. Is this possible?
  7. Thanks! It seems to be working great! In case anyone is curious, this is what I have done... <?php $articleSize = strlen($article); // # of characters in the article $featureSize = 650; // approx. # of article characters that equal the height of the average featured item $featureEq = $articleSize/$featureSize; $featureQty = round($featureEq); //# of features to post $i=1; while( $i <= $featureQty ){ echo "\<?php include 'feature$i.php' ?\><br/>"; $i++; } //end of while ?>
  8. Is there way to count the number of characters in a string? Perhaps I could get the same result that way as the content in question are text articles.
  9. This is probably a stupid question, but I'm curious to know if there is a way to automatically determine the height of each page? I asking because I have a site with a main body column and a side column and hate it when there is blank space vertical on one side of the other just because the content of one of the columns is larger than the other. I was hoping if there is a way to determine how tall the page is then I could create a PHP formula to include a certain number of content features along the side column based on the page height. Perhaps there's a different way to do this... any ideas?
  10. I'm not an expert, but this is the code I used to get my paginations to work... (this is assuming your search fields are "s_title" and "s_topic") At top of page session_destroy(); //Setting session variables if( isset( $_POST[ 's_title' ] ) | isset( $_POST[ 's_topic' ] ) ) { $_SESSION['s_title'] = $_POST['s_title']; $_SESSION['s_topic'] = $_POST['s_topic']; } Then I put my search query, then... ////////// START Page Navigation Equations ////////// //results per page $limit = 4; //Sets what we want to pull from database $query_count = "SELECT * FROM tableName WHERE title LIKE '%$s_title%' AND topic LIKE '%$s_topic%' "; //Pulls what we want from the database $result_count = mysql_query($query_count); //This counts the number of items from mysql $totalrows = mysql_num_rows($result_count); if(empty($page)){ $page = 1; } $limitvalue = $page * $limit - ($limit); //Number of Pages $numofpages = $totalrows / $limit; ////////// STOP Page Navigation Equations ////////// In your SELECT statement to pull the records from the database you would use... SELECT * FROM tableName WHERE title LIKE '%$s_title%' AND topic LIKE '%$s_topic%' ORDER BY title ASC LIMIT $limitvalue, $limit And then use this where you want your navigation bar... /////////////////////// Page Navigation /////////////////////// echo("<br>Page Navigation: "); if($page != 1){ $pageprev = $page - 1; echo("<a href=\"page.php?page=$pageprev &title=$s_title &topic=$s_topic\"><<</a> "); }else echo("<font color=\"#cccccc\"><<</font> "); //Printing Actual Page #'s if($numofpages != 1){ for($i = 1; $i <= $numofpages; $i++){ if($i == $page){ echo(" <b>".$i."</b> "); }else{ echo(" <a href=\"page.php?page=$i &title=$s_title &topic=$s_topic\">$i</a> "); } } // This ends the for loop } // end of if if(($totalrows % $limit) >= 1){ if($i == $page){ echo(" <b>".$i."</b> "); }else{ echo(" <a href=\"page.php?page=$i &title=$s_title &topic=$s_topic\">$i</a> "); } } // Ends the if statement //Setting up "NEXT" link if(($totalrows - ($limit * $page)) > 0){ /* This statement checks to see if there are more rows remaining, meaning there are pages in front of the current one. */ $pagenext = $page + 1; echo(" <a href=\"page.php?page=$pagenext &title=$s_title &topic=$s_topic\"> >></a>"); }else{ echo(" <font color=\"#cccccc\">>></font>"); } mysql_free_result($result);
×
×
  • 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.