If someone could take a look at this and see if there is anything wrong. For some reason when i merge the images, 1 stays normal and 3 have color distortions.
What i am trying to do is to take a image description and add it to the bottom of the image. If i merge the text to the original image it turns out ok but, i am then blocking some of the image. So, my thought was to make a 3rd image then add the original image and then add the text to the bottom and when i do that the color becomes distorted.
Any help / comments are appreciated.
I have been pouring over the code and making all kinds of versions trying to find out what i am doing and, i just can NOT find out what the issue is.
You can find @
http://dewcansam.dyndns.org/prj/imgDescription/imgDescription_test_v-1-2.php
http://dewcansam.dyndns.org/prj/imgDescription/imgDescription_test_v-1-3.php
source of v.1.3
<?php
/**
* @date 2011-01-08 20:13:19
* @version v.1.3
* @author Christopher L. Smith
* @file
* {DESCRIPTION - PURPOSE}
1a. load the orginial image
1b. figure out the size of the orginial image
2a. load the info from the text file or database
2b. figure out the size of the text image
2c. create image from text
3a. create a new image using the sizes of the two images
3b. merge the orgnl image
3c. merge the text image
3d. display the completed image
*
* @short {SUBJECT}
* @details {detailed decription}
*
* @attention { attention text }
* @todo {MODIFIED}
* @todo {MODIFIED 2}
*
* @bug {BUG 1}
* @bug {BUG 2}
* @warning {WARNING 1}
* @warning {WARNING 2}
*
*/
/// set the files to deal with...
$filenames = array(
"3077",
"76147",
"2006-01-21__131242__img_8117.jpg.39040",
"2209.1291310017",
);
$newid = $_GET["id"];
if (($newid < 1) || ($newid > count($filenames))){
$newid = 1;
}
$fileid = $newid - 1;
$fontFamily = array(
"verdana.ttf",
"arial.ttf",
"andalemo.ttf",
"BPmonoBold.ttf",
"Anonymous Pro B.ttf",
);
$font = "./" . $fontFamily[4-1];
$fontsize = 10;
/******************************************************
* Start working with the orgnl picture
*/
$pic = $filenames[$fileid] . ".jpg";
$imgOrgnl = imageCreateFromJpeg($pic);
$imgOrgnl_w = imageSX($imgOrgnl);
$imgOrgnl_h = imageSY($imgOrgnl);
//echo "$imgOrgnl_w <br/>";
//echo "$imgOrgnl_h <br/>";
/******************************************************
* Start working with the description text...
*/
$filename = $filenames[$fileid] . ".txt";
/// $fileinfo becomes the description that is going to be stored on the bottom of the picture
$fileinfo = file($filename);
$quote = "";
$quote .= "RailPictures.net";
$quote .= " \ Image Copyright © " . trim($fileinfo[19]);
$quote .= " \ id = " . trim($fileinfo[0]);
$quote .= "\r\n";
$quote .= trim($fileinfo[5]);
$quote .= " \ " . trim($fileinfo[6]);
$quote .= " \ " . trim($fileinfo[10]);
$quote .= " \ " . trim($fileinfo[12]);
$quote .= "\r\n";
$quote .= wordwrap(trim($fileinfo[23]), 125);
$dims = imageTtfBbox($fontsize, 0, $font, $quote);
$padding_w = 15;
$padding_h = 5;
//$quote_w = $dims[4] - $dims[6] + $padding_w;
$quote_w = $imgOrgnl_w;
$quote_h = $dims[3] - $dims[5] + $padding_h;
$quote_x = 0 + ($padding_w / 2);
$quote_y = $fontsize + ($padding_h);
$quoteImg = imageCreateTrueColor($quote_w, $quote_h);
/**
* Set the background and font colors...
* Then set $bgcolor to transparent
*/
$bgcolor = imageColorAllocate($quoteImg, 000, 000, 000);
$fontcolor = imageColorAllocate($quoteImg, 255, 255, 255);
imageFilledRectangle($quoteImg, 0, 0, $quote_w, $quote_h, $bgcolor);
//imageColorTransparent($quoteImg, $bgcolor);
imageTtfText($quoteImg, $fontsize, 0, $quote_x, $quote_y, $fontcolor, $font, $quote);
/**
* Set the margins for the stamp and get the height/width of the stamp image...
*/
$marge_lr = 20;
$marge_tb = 20;
$marge = 20;
/******************************************************
* Start working with the new image...
*/
$imgNew = imageCreate($imgOrgnl_w, ($imgOrgnl_h + $quote_h - 17));
$bgcolorNew = imageColorAllocate($imgNew, 000, 000, 000);
imageColorTransparent($imgNew, $bgcolorNew);
//echo imagesX($imgNew) . "<br/>";
//echo imagesY($imgNew) . "<br/>";
/**
* dst_x = left / right
* dst_y = top / bottom ( up / down )
* int imagesx ( resource $image )...
* Returns the width of the given image resource...
* After figuring out that generally we only only use 5 postions,
* top-left, top-right, bottom-left, bottom-right and centered.
* I wrote a function that just takes what corner you want and returns
* the position.
*/
//$dst_x = 20; // for left
//$dst_x = imagesx($imgOrgnl) - imagesx($quoteImg) - 20; // for right
$dst_x = pickCorner($quoteImg, $imgNew, "left", 0);
//$dst_y = 20; // for top
//$dst_y = imagesy($imgOrgnl) - imagesy($quoteImg) - 20; // for bottom
$dst_y = pickCorner($quoteImg, $imgNew, "bottom", 0);
$sx = 0;
$sy = 0;
$sw = imagesX($quoteImg);
$sh = imagesY($quoteImg);
$opacity = 100;
imageCopyMerge($imgNew, $imgOrgnl, 0, 0, 0, 0, $imgOrgnl_w, $imgOrgnl_h, 100);
imageCopyMerge($imgNew, $quoteImg, $dst_x, $dst_y, $sx, $sy, $sw, $sh, 100);
if(!headers_sent()){
displayImage($imgNew);
}
function displayImage($im){
/* Output and free memory... */
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
}
/**
* @date 2010-12-29 21:45:51
* @version v.1.2
* @author Christopher L. Smith
*
* pickCorner() takes a corner that you choose and returns a position.
* in other words call it like this:
* $pos_y = pickCorner($img, $img, "top");
* $pos_x = pickCorner($img, $img, "left");
* and you now have the x,y of the top-left corner...
*
* @todo CLS 2010-12-29 21:44:37 + Added the $padding param
*
* @param resource $srcimg The image handler of the source
* image.
* @param resource $dstimg The image handler of the destination
* image.
* @param string $corner A string representing the position can
* be one of the following " l r xc t b yc"
* @param int $padding or margin The distance from the edge.
*
* @return int A number indicating the postion.
*
*/
function pickCorner($srcimg, $dstimg, $corner, $padding = "20") {
switch ($corner) {
case "left":
return $pos = $padding; // for left
case "right":
return $pos = imagesx($dstimg) - imagesx($srcimg) - $padding; // for right;
case "center_x":
return $pos = (imagesx($dstimg)/2) - (imagesx($srcimg)/2) - $padding; // for center;
case "top":
return $pos = $padding; // for top;
case "bottom":
return $pos = imagesy($dstimg) - imagesy($srcimg) - $padding; // for bottom;
case "center_y":
return $pos = (imagesy($dstimg)/2) - (imagesy($srcimg)/2) - $padding; // for center;
}
}