Results 1 to 4 of 4

Thread: How to modify an existing images in PHP

  1. #1
    Join Date
    Feb 2009
    Posts
    78

    How to modify an existing images in PHP

    hie,

    I want to ask you'll about the code in PHP that will help me to modify the exising images. Can anybody provide me the PHP code to do the same ?

    thanks...

  2. #2
    Join Date
    Feb 2008
    Posts
    1,856

    Re: How to modify an existing images in PHP

    Modifying an Existing Image in PHP

    To use an existing GIF, JPEG or PNG image as a canvas on which you add additional elements, use one of the following functions instead of imagecreate().

    imagecreatefromgif ( string $filename )
    imagecreatefromjpeg ( string $filename )
    imagecreatefrompng ( string $filename )

    For example, if you created a GIF file called "mytemplate.gif", the function can be called as follows:

    $myimage = imagecreatefromgif ( "mytemplate.gif" );

  3. #3
    Join Date
    Apr 2008
    Posts
    1,949

    Re: How to modify an existing images in PHP

    Modifying a image is very similar to the form to add the image except for the image thumbnail. Clicking on the thumbnail will call the javascript function viewLargeImage() which will open a popup displaying the full-sized image. If you checkout the form code you can see that we use htmlspecialchars() function when printing the image description in the textarea.

    After you click the "Modify Image" button we continue saving the new information and also save the new image ( if a new one is provided ). The process is just a repetition of the code to modify album data and image. The difference is that now we modify two images, the full-sized image and the thumbnail.

    Code:
    <!-- google_ad_section_start(weight=ignore) --> 
    // ... some code here 
    
    if (isset($_POST['txtTitle'])) {
       $albumId  = $_POST['cboAlbum'];
       $imgTitle = $_POST['txtTitle'];
       $imgDesc  = $_POST['mtxDesc'];
    
       if ($_FILES['fleImage']['tmp_name'] != '') {
          $images = uploadImage('fleImage', GALLERY_IMG_DIR);
    
          if ($images['image'] == '' && $images['thumbnail'] == '') {
             echo "Error uploading file";
             exit;
          }
    
          $image     = "'" . $images['image'] . "'";
          $thumbnail = "'" . $images['thumbnail'] . "'";
    
          $sql = "SELECT im_image, im_thumbnail
                  FROM tbl_image 
                  WHERE im_id = $imgId";
    
          $result = mysql_query($sql) 
                    or die('Error, get image info failed. ' . 
                             mysql_error());
          $row = mysql_fetch_assoc($result);
          unlink(GALLERY_IMG_DIR . $row['im_image']);
          unlink(GALLERY_IMG_DIR . 'thumbnail/' . $row['im_thumbnail']);
       } else {
          // the old image is not replaced
          $image     = "im_image";
          $thumbnail = "im_thumbnail";
       }
    
       if (!get_magic_quotes_gpc()) {
          $albumName = addslashes($albumName);
          $albumDesc = addslashes($albumDesc);
       } 
    
       $sql = "UPDATE tbl_image 
               SET im_album_id    = $albumId, 
                   im_title       = '$imgTitle', 
                   im_description = '$imgDesc', 
                   im_image       = $image, 
                   im_thumbnail   = $thumbnail, 
                   im_date        = NOW()
               WHERE im_id = $imgId";
    
       mysql_query($sql) or die('Error, update image failed : ' .
                                mysql_error()); 
    
       echo "<script>window.location.href = 'index.php?page=image-detail&imgId=$imgId';</script>";
    }
    // ... more code here 
    <!-- google_ad_section_end -->

  4. #4
    Join Date
    May 2008
    Posts
    2,302

    Re: How to modify an existing images in PHP

    If you want modify the contrast and colours of the image in php -

    Here are some of the examples (the jpeg image of house is considered as instance)

    -----------------------------------------------------------------
    <?php
    exec("convert House.jpg -fill black -colorize 15% colorize.png");
    ?>
    -----------------------------------------------------------------
    <?php
    exec("convert House.jpg -contrast-stretch 2% stretch.png");
    ?>
    -----------------------------------------------------------------
    <?php
    exec("convert House.jpg -level 5%,95%,0.8 level.png");
    ?>
    -----------------------------------------------------------------
    <?php
    exec("convert House.jpg -normalize normalize.png");
    ?>
    -----------------------------------------------------------------
    <?php
    exec("convert House.jpg -sigmoidal-contrast 3,75% sigmoidal.png");
    ?>
    -----------------------------------------------------------------

Similar Threads

  1. How to upgrade existing Mac OS to OS X Lion
    By The Remover in forum Operating Systems
    Replies: 3
    Last Post: 28-05-2012, 01:55 PM
  2. How to add images to Google Images
    By Monty1 in forum Tips & Tweaks
    Replies: 2
    Last Post: 14-02-2011, 12:15 PM
  3. Replies: 3
    Last Post: 08-08-2009, 10:48 AM
  4. How 3G different from existing services ?
    By RohanS in forum India BroadBand
    Replies: 3
    Last Post: 04-03-2009, 11:57 AM
  5. Add 2 GB of ram to my existing 2 GB
    By Silent~Kid in forum Motherboard Processor & RAM
    Replies: 5
    Last Post: 27-02-2009, 09:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •