MySQL
  Home arrow MySQL arrow Page 5 - Online Photo Album Development using PHP and GD: Part 1
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MYSQL

Online Photo Album Development using PHP and GD: Part 1
By: Frank Manno
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 36
    2004-04-22


    Table of Contents:
  • Online Photo Album Development using PHP and GD: Part 1
  • Photo Sizing
  • Photo Class
  • To Gif or Not to Gif
  • Resizing Images
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Online Photo Album Development using PHP and GD: Part 1 - Resizing Images
    ( Page 5 of 6 )

    Again, we make use of GD's imagecreatetruecolor() to create a pointer to a true-colored image.

    imagecopyresampled($tmp_resize, $this->img, 0, 0, 0, 0, RESIZE_WIDTH, RESIZE_HEIGHT, $this->width, $this->height);
    imagedestroy($this->img);
    $this->resize = $tmp_resize;

    We then resize our image to the specified size, passing to it the temporary image pointer, the original image, and the 4 parameters dealing with the co-ordinates and size (similar to the ones passed in the setThumbnail() function.

    GD has a built-in function to destroy the original image uploaded. We'll use this function once our image has been resized, followed by assigning the value of $tmp_resize, to our resized image object ($this->resize).

    /*****
    * Copies thumbnail image to specified thumbnail directory.
    * Sets permissions on file
    */
    function copyThumbImage(){
    imagejpeg($this->thumb, $this->thumbnail);
    if(!@copy($this->thumbnail, THUMB_BASE . $this->thumbnail)){
    echo("Error processing file... Please try again!");
    return false;
    }
    if(!@chmod($this->thumbnail, 666)){
    echo("Error processing file... Please try again!");
    return false;
    }
    if(!@unlink($this->thumbnail)){
    echo("Error processing file... Please try again!");
    return false;
    }
    return true;
    }

    Because we're not storing our images in a database, we need to copy the file over to our new images to our desired directories, specified in our constant variables.

    imagejpeg($this->thumb, $this->thumbnail);

    The imagejpeg() function will actually write the JPEG file information to a file that will now reside in the filesystem. We pass, as arguments, the thumbnail pointer ($this->thumb) and the object which will represent the actual thumbnail file ($this->thumbnail).

    We then copy the image to our thumbnail directory, set the desired permissions (making use of PHP's chmod() function), and unlink/delete the temporary thumbnail image.

    /*****
    * Copies the resized image to the specified images directory.
    * Sets permissions on file.
    */
    function copyResizedImage(){
    imagejpeg($this->resize, $this->converted);
    if(!@copy($this->converted, IMAGE_BASE . $this->converted)){
    echo("Error processing file... Please try again!");
    return false;
    }
    if(!@chmod($this->converted, 666)){
    echo("Error processing file... Please try again!");
    return false;
    }
    if(!unlink($this->converted)){
    echo("Error processing file... Please try again!");
    return false;
    }
    // Delete the original uploaded image
    if(!unlink(IMAGE_BASE . $this->image_file)){
    echo("Error processing file... Please try again!");
    return false;
    }
    return true;
    }

    Our copyResizedImage() function is identical to the copyThumbImage() function, except that we work with the resized image rather than the thumbnail.

    /*****
    * Generates a random number. Random number is used to rename
    * the original uploaded image, once resized.
    */
    function getRandom(){
    return "_" . date("dmy_His");
    }

    Our getRandom() function simply returns a string value with the current date and time with a seconds value.

    /*****
    * Returns path to thumbnail image
    */
    function getThumbLocation(){
    return "thumbs/" . $this->random_file;
    }

    The getThumbLocation() function returns the path to our thumbnail image, so that the value may be inserted into our database for retrieval later on.

    /*****
    * Returns path to resized image
    */
    function getImageLocation(){
    return "photos/" . $this->random_file;
    }

    The getImageLocation() returns the path to our resized image, which will be inserted into our database for retrieval later on.



     
     
    >>> More MySQL Articles          >>> More By Frank Manno
     

       

    MYSQL ARTICLES

    - MySQL Security Tips
    - Designing a MySQL Database: Tips and Techniq...
    - The Three Most Important MySQL Queries
    - Null and Empty Strings
    - MySQL Server Tuning Tips and Tricks
    - MySQL Query Optimizations and Schema Design
    - MySQL Benchmarking Tools and Utilities
    - MySQL Benchmarking Concepts and Strategies
    - Take Some Load off MySQL with MemCached
    - MySQL Table Prefix Changer Tool in PHP
    - Using the SIGNAL Statement for Error Handling
    - Error Handling Examples
    - Error Handling
    - Completing a Search Engine with MySQL and PH...
    - Paginating Result Sets for a Search Engine B...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    Stay green...Green IT