- Code: Select all
// find the resize factor.
// This heavily depends on what method we choose for image overflow
// in the future this will also depend on weither we resize up, down or both
$dostretch = false;
if ($settings["overflow"] == "stretch") {
$dostretch = true;
} elseif ($settings["overflow"] == "cut") {
if (((($ox = imagesx($oim)) / $settings["width"]) > (($oy = imagesy($oim)) / $settings["height"]))) {
$resizefactor = $oy / $settings["height"];
} else {
$resizefactor = $ox / $settings["width"];
}
} else {
if (((($ox = imagesx($oim)) / $settings["width"]) > (($oy = imagesy($oim)) / $settings["height"]))) {
$resizefactor = $ox / $settings["width"];
} else {
$resizefactor = $oy / $settings["height"];
}
}
// do the image resize
if ($dostretch) {
imagecopyresampled($nim, $oim, 0, 0, 0, 0, $settings["width"], $settings["height"], $ox, $oy);
} else {
imagecopyresampled($nim, $oim, (($settings["width"] - ($ox/$resizefactor)) /2), (($settings["height"] - ($oy/$resizefactor)) /2), 0, 0, ($ox/$resizefactor), ($oy/$resizefactor), $ox, $oy);
}
// lay over text
if ($settings["textoverlay"]["text"]) {
if ($dostretch) {
$ctx = 4;
$cty = $settings["height"] - 17;
} else {
$ctx = ((($settings["width"] - ($ox/$resizefactor)) /2) + 4);
$cty = ($settings["height"] - ((($settings["height"] - ($oy/$resizefactor)) /2)) - 17);
}
imagestring($nim, 2, $ctx, $cty, $settings["textoverlay"]["text"], $nimcolor["white"]);
}
This is some PGP/GD code for resizing an image.
The resize makes sure that an image is resized onto a new canvas (an image with a set height and width) but contains its proportions, either by cutting the overflow, or by resizing the image to fint, then adding a border around it.
The new goal here is that if $settings["overflow"] == "stretch", the image should be stretched instead of maintaining its proportions, then the text from $settings["textoverlay"]["test"] should be added to the bottom corner of the image, no metther where the image is placed, cause if the image does not fill the new image out, the text overlay should follow the placement of the resized image, not the canvas. This all works, so dont mind that. (teh fallback for neither cut nor stretch is "fill" btw, thats the default fallback)
The error is as this: If you do a "stretch" the image is just black.
Why? (i know it.. its just a mind-challenge)
and btw: this code is copyright apario my emplyer and blahbalhblah.