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...
Printable View
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...
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" );
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 -->
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");
?>
-----------------------------------------------------------------