thing is, i am building a "geochecker" similar to the ones found on the internet (google-it)
basically, my registered member enters some informations about a mystery thing, then my website give him a link to display an image on his "mystery" thing page.
that image is dynamic and needs to show 2 numbers, #of correct answers - and #of incorrect answers
so then future "mystery" thing users have an idead of what to expect in terms of dgree of difficulty.
-------
that beein said, i can successfully render my image, using GD, in full php. Since it’s supposed to load on request from another webpage, it only displays a png header thaat you can call directly with the php name or via an <img src"php-source">
-------
my problem is - inside of MODX, i can’t seem to get the whole thing working as a snippet. (it must have something to do with headers already sent) -- i found a way to ajust this, but i must say i’d rather have only ONE snippet that would either display outside of modx and inside.
so here’s the code.
this is my PHP source that works outside of MODX.
<?php
// Check for input values and check if file exists (txt) on server
if (isset($_GET['gid']) && file_exists("../test/data/". ($_GET['gid']) . ".txt")) {
$fileName = "../test/data/". ($_GET['gid']) . ".txt";
displayImg($fileName);}
else {
displayErrorImg();
}
// Checked, OK! Display image...
function displayImg($tmpfileName) {
$values = explode("\n",file_get_contents($tmpfileName));
$rightAmnt = $values[0];
$wrongAmnt = $values[1];
$image = imagecreatefrompng("../test/checker1_default.png");
// Set Font Size
$font_size = 20;
// Set The Color Of The Outline
$shadow_color = imagecolorallocate($image, 0,0,0);
// Set The Color Of The RIGHT and WRONG Front TEXT
$shadow_right = imagecolorallocate($image, 193,226,61);
$shadow_wrong = imagecolorallocate($image, 255,88,43);
//--------------------------------------------------------------
// Text Outline RIGHT
//--------------------------------------------------------------
ImageTTFText ($image, $font_size, 35, 93, 103, $shadow_color, "../test/arial.ttf",$rightAmnt);
ImageTTFText ($image, $font_size, 35, 93, 105, $shadow_color, "../test/arial.ttf",$rightAmnt);
ImageTTFText ($image, $font_size, 35, 92, 104, $shadow_color, "../test/arial.ttf",$rightAmnt);
ImageTTFText ($image, $font_size, 35, 94, 104, $shadow_color, "../test/arial.ttf",$rightAmnt);
// Front Text Generation RIGHT
ImageTTFText ($image, $font_size, 35, 93, 104, $shadow_right, "../test/arial.ttf",$rightAmnt);
//--------------------------------------------------------------
// Text Outline WRONG
//--------------------------------------------------------------
ImageTTFText ($image, $font_size, 327, 270, 44, $shadow_color, "../test/arial.ttf",$wrongAmnt);
ImageTTFText ($image, $font_size, 327, 270, 46, $shadow_color, "../test/arial.ttf",$wrongAmnt);
ImageTTFText ($image, $font_size, 327, 269, 45, $shadow_color, "../test/arial.ttf",$wrongAmnt);
ImageTTFText ($image, $font_size, 327, 271, 45, $shadow_color, "../test/arial.ttf",$wrongAmnt);
// Front Text Generation WRONG
ImageTTFText ($image, $font_size, 327, 270, 45, $shadow_wrong, "../test/arial.ttf",$wrongAmnt);
//--------------------------------------------------------------
header("Content-type: image/png");
imagepng($image);
return $image;
}
// Checked, BAD! Display BAD image...
function displayErrorImg(){
$image = imagecreatefrompng("../test/checker1_BadUrl.png");
header("Content-type: image/png");
imagepng($image);
return $image;
}
imagedestroy($image);
?>
---------------------------------------------------
If i want to display that image in modx, crazy PNG header characters appear instead of the actual image.
looking around at some modx problems and solutions, i found this fix wich enables me to display my dynamic image inside of modx with the previous script as a snippet. But it’s only good for one thing, prevewing the image result in modx (for the front-end user while setting up the data per example)
<?php
// displays in MODX only
ImagePNG($image,"image.png");
ImageDestroy($image);
$output = '<img src="image.png" border=2> ' . $fileName;
return $output;
?>
So. Essentially... id love to have a modx snippet that can output to browsers outside of modx environment AND use the same snippet, no extra parameters required, to preview the image in modx (just like the fix does so wonderfully)
say you wanted to display that picture on your site... just add [img]http://myModXSite/friendlyUrltoSnippet[/img]
and use the equivalent to display inside of modx ; <img src="[[!snippetCallForImg]]"/>
[EDIT] The previous has been partially dealt with - read on other posts for explanation;
am i crazy? confusing? please tell me... also remember, i have only been coding php for a couple months.
Maybe your script does exactly that, but i don’t seem to understand it properly :/
[EDIT] I understand your script, now;
Thanks!