Hi,
Still working on it. I have only very very recently started looking at the GD functions of PHP, so my skills are certainly lacking. However here are a few scripts I have discovered.
Resizes the image and outputs it directly to a web browser witout saving the file anywhere.
PHP Code:
<?php
// The file
$filename = 'images/picture.jpg';
$percent = 0.25;
// Content type
header('Content-type: image/jpeg');
// Get new dimensions
list($width, $height) = getimagesize($filename);
$new_width = $width * $percent;
$new_height = $height * $percent;
// Resample
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// Output
imagejpeg($image_p, null, 100);
?>
Add the following at the end of the script to save the resized image to a file on your server. The original file is not destroyed.
PHP Code:
$dest="try1.jpg";
imagepng($image_p,$dest);
There are a great deal of terms that I am still unfamiliar with, but the following will replace one color with another in a created image. This is not exactly what we want, but at least we are getting closer. It can be applied to an image, but I do not know how to do that yet.
Code:
<?php
header("Content-type: image/png");
$im = imagecreate(200, 200);
$red = imagecolorallocate($im, 255, 0, 0);
$offblue = imagecolorallocate($im, 90, 90, 200);
imagefill($im, 0, 0, $red);
imagefilledrectangle($im, 10, 10, 40, 40, $offblue);
// above could come from an uploaded image
// find a blue in the image
$newblue = imagecolorclosest($im, 0, 0, 255);
// change it to green
imagecolorset($im, $newblue, 0, 255, 0);
imagepng($im);
imagedestroy($im);
?php>
I got the above code from http://www.phpdig.net/ref/rn25re393.html
Bookmarks