So far I've got the code you see below. I've not yet figured out how
to change the name of the file. I'm creating several images of
different sizes. I need to give them all different names. How do I
control the name?
function makeImage($pathToImage=false, $desiredSize=false) {
if (file_exists($pathToImage)) {
if ($desiredSize) {
// 04-26-03 - This whole next section is off limits till I find out
how to test for image support in the
// PHP build in use - my own hosting company doesn't offer support
for functions like imagecreatefromjpeg.
//
// 05-25-03 - function_exists() is the correct way to test.
//
// 07-22-04 - when images are uploaded, a thumbnail should be
created.
//
// 11-16-04 - I'm going to try to revive this function today and
make it operational.
// It's been in the code but unused for a year and a half.
// Since most PHP installations don't have the GD library, I think
the way to go is
// to simply test for every function.
$controllerForAll = & getController();
$resultsObject = & $controllerForAll->getObject("McResults",
"makeImage");
if (function_exists("getimagesize")) {
if (function_exists("imagecreate")) {
if (function_exists("imagecreatefromjpeg")) {
if (function_exists("imagecopyresized")) {
if (function_exists("imagesx") && function_exists("imagesy")) {
if (function_exists("imagejpeg")) {
if (function_exists("imagecreatefromgif")) {
if (function_exists("imagegif")) {
$size = getimagesize($pathToImage);
// 04-13-03 - Now we make sure we only output the jpgs and
gifs
// 04-13-03 - this next line is to find out if we are
outputting jpg or gif
// WE ONLY OUTPUT JPG AND GIF
if ($size[2] == 1 || $size[2] == 2) {
$oldWidth = $size[0];
$oldHeight = $size[1];
// 11-20-04 - we reset the width to whatever the desired
size is.
// standardImageInsert calls this function 4 times with
values of
// 50, 100, 250, and 400. We then compare the desired size
to the
// old width to get a ratioOfChange which we can then
apply to
// the height to get a propotional change. The division
will
// leave us with a float, but we need an integer for the
// height value, so we hit the result with round().
$newWidth = $desiredSize;
$ratioOfChange = $oldWidth / $desiredSize;
$newHeight = $oldHeight / $ratioOfChange;
$newHeight = round($newHeight);
$newImage = imagecreate($newWidth, $newHeight);
if ($size[2] == 2) {
$srcImage = imagecreatefromjpeg($image);
imagecopyresized($newImage, $srcImage, 0, 0, 0, 0,
$newWidth, $newHeight, imagesx($srcImage), imagesy($srcImage));
imagejpeg($newImage);
} elseif ($size[2] == 1) {
$srcImage = imagecreatefromgif($image);
imageCopyResized($newImage, $srcImage, 0, 0, 0, 0,
$newWidth, $newHeight, imagesx($srcImage), imagesy($srcImage));
imagegif($newImage);
}
}
}
}
}
}
}
}
}
}
} else {
$resultsObject->error("In makeImage, the second parameter should
have told us what width was desired for this image, but it did not.",
"makeImage");
}
} else {
if ($pathToImage == "") {
$resultsObject->error("In makeImage(), the first parameter should
have told us where to find this image (what path to it), but it did
not.", "makeImage");
} else {
$resultsObject->error("In makeImage(), we were told to resize an
image called '$pathToImage' but the image didn't seem to exist on the
server.", "makeImage");
}
}
}