Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



How to modify an existing images in PHP

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 28-04-2009
Member
 
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...

Reply With Quote
  #2  
Old 28-04-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
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" );
Reply With Quote
  #3  
Old 28-04-2009
Member
 
Join Date: Apr 2008
Posts: 1,948
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 -->
Reply With Quote
  #4  
Old 28-04-2009
Member
 
Join Date: May 2008
Posts: 2,293
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");
?>
-----------------------------------------------------------------
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to modify an existing images in PHP"
Thread Thread Starter Forum Replies Last Post
How to upgrade existing Mac OS to OS X Lion The Remover Operating Systems 3 28-05-2012 02:55 PM
How to add images to Google Images Monty1 Tips & Tweaks 2 14-02-2011 01:15 PM
Unable to modify the databse with the same name as an existing database Reckon Software Development 3 08-08-2009 11:48 AM
How 3G different from existing services ? RohanS India BroadBand 3 04-03-2009 12:57 PM
Add 2 GB of ram to my existing 2 GB Silent~Kid Motherboard Processor & RAM 5 27-02-2009 10:15 AM


All times are GMT +5.5. The time now is 09:30 AM.