Help - Search - Members - Calendar
Full Version: Modifying .png Image
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
Runickitty
is this easy? Is there a special name for it? Because I can't find anything when I search o.o

So you can change the colour of an image through php, but I don't know exactly how to apply the chosen colour to the image
Jacob
I do not understand what you mean. :S

Jacob.
Runickitty
http://v3.zetapets.com/blah/demonstrate.php

Something like this
Jacob
Ah, so you would like to create dynamic images via PHP? Google for "Dynamic PHP images tutorial" and that should get you some results worth reading.

Jacob.
Runickitty
thank you happy.gif smile.gif
noxus
most of the time GD dont work in anything outside of IE browser
Andrew
lmfao what are you talking about noxus. GD is ran through php which is all server side. It doesn't matter what browser you use.

Either think before you post or explain better what your saying. Because as it is you're making yourself look pretty dumb.
Jacob
QUOTE(noxus @ Sep 18 2008, 12:33 PM) *
most of the time GD dont work in anything outside of IE browser

:|. What on earth are you talking about?

Jacob.
noxus
alot of sites with authorization login/registration pics for input fields. remove them if you go back to the site in opera or firefox. you`ll just have a blank page saying image cannot be displayed. image has errors or image is empty
Alex
Sounds like you've got the Content-Type header wrong, or some such, there is no reason that correctly written GD will error in browsers other than IE. If that does happen, you're doing it wrong - not GD.
noxus
nope. its just the browsers. search for "content type png" and theres loads of places saying they dont work, if you want it working. just miss out the header(content-type...) all together
Alex
Show me an example of it not working, code included please.
Andrew
QUOTE(noxus @ Sep 18 2008, 02:42 PM) *
nope. its just the browsers. search for "content type png" and theres loads of places saying they dont work, if you want it working. just miss out the header(content-type...) all together

That is a user error. That's like trying to drive a car with no steering wheel.

noxus
its just all the cheap browsers. you can create modified images using GD. for authorization codes etc.. as soon as you add header(content-type); like your suppose to do. the page wont load outside of IE. without the header(); line. the page will work as it should in all browsers
Andrew
I just did this, and it works fine.
Goto http://trippin.uni.cc/generator.php?text=retard=noxus and it loads it just fine in firefox3 AND IE7
Please note that you can change the text after the text=

And here's my code: I got it off a tutorial, but either way it works and there is the header line.
CODE
<?php
header('Content-type: image/png');
$text = $_GET['text'];

$im = imagecreatefrompng ("userbar.png");

if($text == "ADMINISTRATOR"){ //if administrator
    $color = imagecolorallocate($im, 255, 0, 0); //red
    }
elseif($text == "MODERATOR"){ //if moderator
    $color = imagecolorallocate($im, 0, 0, 255); //blue
    }
elseif($text == "JUNKIE"){ //if junkie
    $color = imagecolorallocate($im, 0, 0, 0); //black
    }
else { //something else...
    $color = imagecolorallocate($im, 0, 128, 0); //green
    }
    
$font = 'font.ttf'; //font file
$fontsize = 26; //font size
$stringsize = imagettfbbox($fontsize, 0, $font, $text); //calculate the pixel of the string
$dx = (imagesx($im)) - (abs($stringsize[2]-$stringsize[0])) - 130; //calculate the location to start the text
imagettftext($im, $fontsize, 0, $dx, 33, $color, $font, $text);
imagepng($im);
imagedestroy($im);
?>


Please do research before you make accusations.

I would post a direct link to the image but zymic has disabled the ability to post dynamic links in the img tags... so suffer with viewing the page directly.
EMOruffino
QUOTE(Trippin7464 @ Sep 18 2008, 05:37 PM) *
I just did this, and it works fine.
Goto http://trippin.uni.cc/generator.php?text=retard=noxus and it loads it just fine in firefox3 AND IE7
Please note that you can change the text after the text=

And here's my code: I got it off a tutorial, but either way it works and there is the header line.
CODE
<?php
header('Content-type: image/png');
$text = $_GET['text'];

$im = imagecreatefrompng ("userbar.png");

if($text == "ADMINISTRATOR"){ //if administrator
    $color = imagecolorallocate($im, 255, 0, 0); //red
    }
elseif($text == "MODERATOR"){ //if moderator
    $color = imagecolorallocate($im, 0, 0, 255); //blue
    }
elseif($text == "JUNKIE"){ //if junkie
    $color = imagecolorallocate($im, 0, 0, 0); //black
    }
else { //something else...
    $color = imagecolorallocate($im, 0, 128, 0); //green
    }
    
$font = 'font.ttf'; //font file
$fontsize = 26; //font size
$stringsize = imagettfbbox($fontsize, 0, $font, $text); //calculate the pixel of the string
$dx = (imagesx($im)) - (abs($stringsize[2]-$stringsize[0])) - 130; //calculate the location to start the text
imagettftext($im, $fontsize, 0, $dx, 33, $color, $font, $text);
imagepng($im);
imagedestroy($im);
?>


Please do research before you make accusations.

I would post a direct link to the image but zymic has disabled the ability to post dynamic links in the img tags... so suffer with viewing the page directly.


omg it works! tongue.gif
noxus
mine works. unless i have header(content-type) then all the lame browsers like firefox extra will just return a page with some guff about a blank or errored image. just like many. on any search engine. its nothing to do with lame code. its the lame browsers. just like they cant handle css properly
Alex
Another post, still no example with code. And with proof to the contrary in trippin's post above.

What we have here is a troll. Ignore him.
Andrew
I just wanted to add that I have a header (content type) in my code, and lo and behold it works. Unless you can show proof of code not working ( like alex has asked for multiple times ) there isn't any point talking to you.
Jacob
Should we take away his posting abilities? smile.gif

Jacob.
noxus
my nuke is mine. and the most powerfull, cleanest and most functional 1 around

my calandar

CODE
Calandar();

function Calandar() {

    $cNday = remZeroNum(date("d", time()));
        
    $Tday = date("d", time());
    $cday = date("D", time());
    $month = date("m", time());
    $year = date("Y", time());

    $lday = date("D", daysago($cNday));

    $daysmnth = getdaysinmonth($month);

    echo "<table>";
    echo "<tr class=\"calandartitle\">";
    echo "<td align=\"center\" colspan=\"7\">". date("F")."</td>";
    echo "</tr>";
    echo "<tr class=\"calandardays\">";
    echo "<td align=\"center\" style=\"color:#FF0000;\">S</td>";
    echo "<td align=\"center\">M</td>";
    echo "<td align=\"center\">T</td>";
    echo "<td align=\"center\">W</td>";
    echo "<td align=\"center\">T</td>";
    echo "<td align=\"center\">F</td>";
    echo "<td align=\"center\" style=\"color:#FF0000;\">S</td>";

    echo "</tr>";
        
    if ($lday == "Sun") { $stnum = 2; }
    if ($lday == "Mon") { $stnum = 3; }
    if ($lday == "Tue") { $stnum = 4; }
    if ($lday == "Wed") { $stnum = 5; }
    if ($lday == "Thu") { $stnum = 6; }
    if ($lday == "Fri") { $stnum = 7; }
    if ($lday == "Sat") { $stnum = 1; }

    $t=1;
    for($i=1;$i<=42;$i++) {

        if ($i == 1 || $i == 8 || $i == 22 || $i == 29 || $i == 36) {
                
            echo "<tr>";

        }
            
        if ($i >= $stnum && $t <= $daysmnth) {

            if ($t < 10) {

                $eday = "0$t";
                    
            }
                
            if ($t >= 10) {

                $eday = "$t";
                    
            }
    
            if ($t && $t != $Tday) {
                    
                echo "<td align=\"center\" class=\"calandarnum\">";
                    
                echo $t++;

            } else if ($eday == $Tday) {
                    
                echo "<td align=\"center\" class=\"calandarT\">";
                    
                echo $t++;

            } else if (!$t) {
                    
                echo $t++;
                    
                echo "<td>";

            }

            echo "</td>";

        } else {
                
            echo "<td></td>";
                
        }
            
        if ($i == 7 || $i == 14 || $i == 21 || $i == 28 || $i == 35) {
                
            echo "</tr>";

        }

    }
        
    echo "</table>";

}
      
function remZeroNum($in_num) {
    
    $tmp = substr($in_num, 0, 1);

    if ($tmp == "0") {

        $in_num = substr($in_num, 1, strlen($in_num));

    }

    return $in_num;

}

function daysago($val) {
    
    $v = $val *(86400);
    $days = time() - $v;
    
    unset($val);
    unset($v);
    
    return($days);
}

function getdaysinmonth($in_mnth = null) {

    $array[1] = 31;
    $array[2] = 28;
    $array[3] = 31;
    $array[4] = 30;
    $array[5] = 31;
    $array[6] = 30;
    $array[7] = 31;
    $array[8] = 31;
    $array[9] = 30;
    $array[10] = 31;
    $array[11] = 30;
    $array[12] = 31;

    if ($in_mnth != null) {
        
        $in_mnth = remZeroNum($in_mnth);
        return $array[strtolower($in_mnth)];
    
    }
    
    return $array;

}
Andrew
That has nothing to do with GD.
Brandon
QUOTE(NaRzY @ Sep 19 2008, 11:09 AM) *
Should we take away his posting abilities? smile.gif

Jacob.

No!..

Jacob.
noxus
its the best calandar you`ll ever find. and the only with the smallest code
swordz
You could make the code much shorter than that, simply by using arrays and array keys. e.g

CODE
if ($lday == "Sun") { $stnum = 2; }
if ($lday == "Mon") { $stnum = 3; }
if ($lday == "Tue") { $stnum = 4; }
if ($lday == "Wed") { $stnum = 5; }
if ($lday == "Thu") { $stnum = 6; }
if ($lday == "Fri") { $stnum = 7; }
if ($lday == "Sat") { $stnum = 1; }


could be written as:

CODE
$stnumday = array('Sun' => 2, 'Mon' => 3, 'Tue' => 4, 'Wed' => 5, 'Thu' => 6, 'Fri' => 7, 'Sat' => 1);
$stnum = $strnumday[$lday];


I haven't run this, as it's 1am, so there might be a few errors, but you get the general idea. This is much shorter code, and much quicker to run. There's quite a few savings like this to made.

swordz
Andrew
Thats all well and awesome swordz but the guy isn't trying to make a calendar, he was asking about modifying a .png image, and then noxus throws in random code for a calendar.

I can't say much because the rest of us got off topic talking about whether GD works or not with the header information supplied (which is does contrary to what noxus says)... but still.
noxus
i originally said that GD`s createimage....() function wont work outside of IE. because most other browser will give you a error message if you have the header(content-type) in the <head></head> like your suppose do.

mine only works in other browsers like firefox etc. if i dont use header(content-type); http://c0re.vndv.com/login.php?op=register
the problem happens to many people if you do a search. so its not lame code. its just the browsers

with the calandar code. giving you the calandar block at the top left
Alex
"if you have the header(content-type) in the <head></head> like your suppose do"

uhh... what? header() must be called before ANY output, and there is likely to be no need to call header if there even was a <head> because the assumed content-type is text/html. You seem to be very confused - if I were you I'd re-read what the PHP manual has to say about GD.
noxus
either way. in some browser GDs create image dont work
Andrew
Still untrue. You obviously need to do as alex says. Unless you can actually provide proof other than saying to Google it, then i'll assume you don't have a clue as to what your talking about.
noxus
many search pages full of many forum posts saying it sometimes dont work isnt proof
Andrew
QUOTE(noxus @ Sep 22 2008, 05:47 PM) *
many search pages full of many forum posts saying it sometimes dont work isnt proof

That's exactly what I said...
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.