...

View Full Version : How to convert a dynamic php image into a simple png.



reuben
06-12-2006, 01:00 AM
Hi guys,

I want to convert my dynamic img:
http://hyip-status.com/monitor/img.php?id=181

Into a simple dynamic png which will be held here:
http://hyip-status.com/monitor/img/181.png



<?php
$img=imagecreatefrompng('gfx/banner.png');
if(strlen($_GET['id']))
{
include('./config/config.php');
$id=$_GET['id'];
if($result=mysql_unbuffered_query("SELECT * FROM `payouts` WHERE `id_program`='$id' ORDER BY `data` DESC, `id_payout` DESC"))
{
$i=0;
$inv=0;
$pay=0;
while($row=mysql_fetch_assoc($result))
{
if ($row['status']==0)
$inv = $inv + $row['kwota'];
else
$pay = $pay + $row['kwota'];
}
}
$table = "programs";
if($result=mysql_query("SELECT `nazwa`, `rating`, `status`,`premium`,`total`,`risk`,`data` FROM `programs` WHERE `id_program`='". $_GET['id'] ."' AND `blacklist`=''") and $payout=mysql_query("SELECT `data` FROM `payouts` WHERE `id_program`='". $_GET['id'] ."' AND `status`!='0' ORDER BY `data` DESC LIMIT 1"))
{
if(mysql_num_rows($result)==1)
{
$inv='Investment: $'.$inv.'';
$pay='Returns: $'.$pay.'';
$date=date("F j, Y");
$monitored=mysql_result($result, 0, 6);
$name=mysql_result($result, 0, 0);
$rating=('User Rate: '.mysql_result($result, 0, 1));
$status=mysql_result($result, 0, 2);
$type=mysql_result($result, 0, 3);
$ratio='Payout Ratio: '.mysql_result($result, 0, 4).'%';
$risk=mysql_result($result, 0, 5);
//Finding Monitored days.
// Convert each of them into strings
$date2 = date("Y-m-d");
$string1 = strtotime($monitored); // or the variable $date1
$string2 = strtotime($date2); // or the variable $date2

// Subtract the difference
$difference = $string2-$string1;

// divide by the time period you wish to check

$DifferenceInDays = ($difference/86400);
settype($DifferenceInDays, "string");
$test = '0'.strstr($DifferenceInDays, ".");
settype($test, "float");
If ($test > 0){
settype($DifferenceInDays, "float");
$DifferenceInDays=$DifferenceInDays-$test;
}
$MonitoredFor = 'Monitored: '.$DifferenceInDays.' Days';
//END MONITORED DAYS
if(mysql_num_rows($payout)==1){
$last_payout=mysql_result($payout, 0, 0);
if ($last_payout==date("Y-m-d"))
{
$last_payout='Today';
}
}
else
$last_payout='No Payouts';

if($type=='*')
$type='Type: Premium';
else
$type='Type: Normal';
mysql_free_result($result);
$img=imagecreatefrompng('gfx/banner.png');
$white=imagecolorallocate($img, 255, 255, 255);
$green=imagecolorallocate($img, 23, 221, 23);
$name=((strlen($name)>15) ? substr($name, 0, 13). '...' : $name);
$x = floor((ImageSX($img) / 2) - ((ImageFontWidth(3) * strlen($name)) / 2));
$datealign = floor((ImageSX($img) / 2) - ((ImageFontWidth(3) * strlen($date)) / 2));
$ratingalign = floor((ImageSX($img) / 2) - ((ImageFontWidth(2) * strlen($rating)) / 2));
$typealign = floor((ImageSX($img) / 2) - ((ImageFontWidth(2) * strlen($type)) / 2));
$invalign = floor((ImageSX($img) / 2) - ((ImageFontWidth(2) * strlen($inv)) / 2));
$payalign = floor((ImageSX($img) / 2) - ((ImageFontWidth(2) * strlen($pay)) / 2));
$ratioalign = floor((ImageSX($img) / 2) - ((ImageFontWidth(2) * strlen($ratio)) / 2));
$lpayalign = floor((ImageSX($img) / 2) - ((ImageFontWidth(3) * strlen($last_payout)) / 2));
$monitoredalign = floor((ImageSX($img) / 2) - ((ImageFontWidth(2) * strlen($MonitoredFor)) / 2));
imagestring($img, 3, $x, 64, $name, $white);
imagestring($img, 3, $datealign, 103, $date, $black);
imagestring($img, 2, $monitoredalign, 117, $MonitoredFor, $black);
imagestring($img, 2, $typealign, 129, $type, $black);
imagestring($img, 2, $ratingalign, 140, $rating, $black);
imagestring($img, 2, $invalign, 152, $inv, $black);
imagestring($img, 2, $payalign, 164, $pay, $black);
imagestring($img, 2, $ratioalign, 176, $ratio, $black);
imagestring($img, 2, 24, 189, 'Last Payout:', $black);
imagestring($img, 3, $lpayalign, 202, $last_payout, $lpaycolor);
if ($p=imagecreatefromgif('./gfx/icons/status_'. $status .'.gif'))
{
imagecopyresampled($img, $p, 5, 84, 0, 0, 110, 16, 110, 16);
imagedestroy($p);
}
if ($g=imagecreatefromgif('./gfx/icons/risk_'. $risk .'.gif'))
{
imagecopyresampled($img, $g, 36, 222, 0, 0, 47, 15, 47, 15);
imagedestroy($g);
}
}
else
{}
}
}
header("Content-type: image/png");
imagepng($img);
?>


Is there anyway to do this?

rlemon
06-12-2006, 03:52 PM
createDynamicPNG.php


<?php
$outputFile = "image.png";
$filename = "dynamicImage.php";
$contents = file_get_contents($filename);
$handle = fopen($outputFile,"w");
fwrite($handle, $contents);
fclose($handle);
?>


dynamicImage.php


<?php
$img=imagecreatefrompng('gfx/banner.png');
if(strlen($_GET['id']))
{
include('./config/config.php');
$id=$_GET['id'];
if($result=mysql_unbuffered_query("SELECT * FROM `payouts` WHERE `id_program`='$id' ORDER BY `data` DESC, `id_payout` DESC"))
{
$i=0;
$inv=0;
$pay=0;
while($row=mysql_fetch_assoc($result))
{
if ($row['status']==0)
$inv = $inv + $row['kwota'];
else
$pay = $pay + $row['kwota'];
}
}
$table = "programs";
if($result=mysql_query("SELECT `nazwa`, `rating`, `status`,`premium`,`total`,`risk`,`data` FROM `programs` WHERE `id_program`='". $_GET['id'] ."' AND `blacklist`=''") and $payout=mysql_query("SELECT `data` FROM `payouts` WHERE `id_program`='". $_GET['id'] ."' AND `status`!='0' ORDER BY `data` DESC LIMIT 1"))
{
if(mysql_num_rows($result)==1)
{
$inv='Investment: $'.$inv.'';
$pay='Returns: $'.$pay.'';
$date=date("F j, Y");
$monitored=mysql_result($result, 0, 6);
$name=mysql_result($result, 0, 0);
$rating=('User Rate: '.mysql_result($result, 0, 1));
$status=mysql_result($result, 0, 2);
$type=mysql_result($result, 0, 3);
$ratio='Payout Ratio: '.mysql_result($result, 0, 4).'%';
$risk=mysql_result($result, 0, 5);
//Finding Monitored days.
// Convert each of them into strings
$date2 = date("Y-m-d");
$string1 = strtotime($monitored); // or the variable $date1
$string2 = strtotime($date2); // or the variable $date2

// Subtract the difference
$difference = $string2-$string1;

// divide by the time period you wish to check

$DifferenceInDays = ($difference/86400);
settype($DifferenceInDays, "string");
$test = '0'.strstr($DifferenceInDays, ".");
settype($test, "float");
If ($test > 0){
settype($DifferenceInDays, "float");
$DifferenceInDays=$DifferenceInDays-$test;
}
$MonitoredFor = 'Monitored: '.$DifferenceInDays.' Days';
//END MONITORED DAYS
if(mysql_num_rows($payout)==1){
$last_payout=mysql_result($payout, 0, 0);
if ($last_payout==date("Y-m-d"))
{
$last_payout='Today';
}
}
else
$last_payout='No Payouts';

if($type=='*')
$type='Type: Premium';
else
$type='Type: Normal';
mysql_free_result($result);
$img=imagecreatefrompng('gfx/banner.png');
$white=imagecolorallocate($img, 255, 255, 255);
$green=imagecolorallocate($img, 23, 221, 23);
$name=((strlen($name)>15) ? substr($name, 0, 13). '...' : $name);
$x = floor((ImageSX($img) / 2) - ((ImageFontWidth(3) * strlen($name)) / 2));
$datealign = floor((ImageSX($img) / 2) - ((ImageFontWidth(3) * strlen($date)) / 2));
$ratingalign = floor((ImageSX($img) / 2) - ((ImageFontWidth(2) * strlen($rating)) / 2));
$typealign = floor((ImageSX($img) / 2) - ((ImageFontWidth(2) * strlen($type)) / 2));
$invalign = floor((ImageSX($img) / 2) - ((ImageFontWidth(2) * strlen($inv)) / 2));
$payalign = floor((ImageSX($img) / 2) - ((ImageFontWidth(2) * strlen($pay)) / 2));
$ratioalign = floor((ImageSX($img) / 2) - ((ImageFontWidth(2) * strlen($ratio)) / 2));
$lpayalign = floor((ImageSX($img) / 2) - ((ImageFontWidth(3) * strlen($last_payout)) / 2));
$monitoredalign = floor((ImageSX($img) / 2) - ((ImageFontWidth(2) * strlen($MonitoredFor)) / 2));
imagestring($img, 3, $x, 64, $name, $white);
imagestring($img, 3, $datealign, 103, $date, $black);
imagestring($img, 2, $monitoredalign, 117, $MonitoredFor, $black);
imagestring($img, 2, $typealign, 129, $type, $black);
imagestring($img, 2, $ratingalign, 140, $rating, $black);
imagestring($img, 2, $invalign, 152, $inv, $black);
imagestring($img, 2, $payalign, 164, $pay, $black);
imagestring($img, 2, $ratioalign, 176, $ratio, $black);
imagestring($img, 2, 24, 189, 'Last Payout:', $black);
imagestring($img, 3, $lpayalign, 202, $last_payout, $lpaycolor);
if ($p=imagecreatefromgif('./gfx/icons/status_'. $status .'.gif'))
{
imagecopyresampled($img, $p, 5, 84, 0, 0, 110, 16, 110, 16);
imagedestroy($p);
}
if ($g=imagecreatefromgif('./gfx/icons/risk_'. $risk .'.gif'))
{
imagecopyresampled($img, $g, 36, 222, 0, 0, 47, 15, 47, 15);
imagedestroy($g);
}
}
else
{}
}
}
header("Content-type: image/png");
imagepng($img);
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum