Image Output Fixed

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Locked
bluesguitarman25
Forum Newbie
Posts: 8
Joined: Tue Jul 03, 2007 9:22 am
Location: PA

Image Output Fixed

Post by bluesguitarman25 »

the multi-layered txt-pic-merge script is fixed. This is a great script for creating images like ID's on the fly:

Code: Select all

mysql_select_db(user_info);
$id = $_POST['email'];
$sql2 = "SELECT * FROM user_info WHERE email ='$id'";
$result = mysql_query($sql2) or die(mysql_error());
$row = mysql_fetch_assoc($result);
if (!$row) {
echo "<br />Nothing to print....";
}

$string = "DOB:     " . $row['dob'];
$string2 = $row['firstname'] . " " . $row['lastname'];
$string3 = $row['region'];
$string4 = $row['language'];
$string5 = $row['greeting'];
$string6 = $row['email'];
$id_num = "ID#  " . $row['id'];
$pix = $row['pix'];

header("Content-type:image/jpeg");
$im     = imagecreatefromjpeg('citizen-blank.jpg');
$logo = imagecreatefromgif('citizen-logo.gif');
$orange = imagecolorallocate($im, 220, 210, 60);
$black = imagecolorallocate($im, 0, 0, 0);
// next line = bg image, font size, x,y, string, color
// set ($im, 5, 20, 30...) for ID#
imagestring($im, 2, 157, 70, $string, $black);
imagestring($im, 2, 157, 80, $string2, $black);
imagestring($im, 2, 157, 90, $string3, $black);
imagestring($im, 2, 157, 100, $string4, $black);
imagestring($im, 2, 157, 110, $string5, $black);
imagestring($im, 2, 157, 120, $string6, $black);
imagestring($im, 5, 10, 30, $id_num, $orange);

// insert upload image here

// The pic file

// Set a maximum height and width
$width = 116;
$height = 165;

// Get new dimensions
list($width_orig, $height_orig) = getimagesize($pix) or die("could not get image dimensions");
if ($width && ($width_orig < $height_orig)) {
    $width = ($height / $height_orig) * $width_orig;
} else {
    $height = ($width / $width_orig) * $height_orig;
}

// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($pix);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig) or die("could not resample");
imagecopymerge($im, $image_p, 20, 67, 0, 0, $width, $height, 100);
imagecopymerge($im, $logo, 10, 137, 0, 0, 56, 56, 100);

// Output
imagejpeg($im);
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Are you asking a question?
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

Post by thiscatis »

I think this should have been a reply on another topic
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

thiscatis wrote:I think this should have been a reply on another topic
Yea I believe so.

Topic Locked.
Locked