Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [MySQL][PHP]imagecolorallocate i instrukcja if
c4ash
post 29.10.2010, 08:45:07
Post #1





Grupa: Zarejestrowani
Postów: 73
Pomógł: 9
Dołączył: 14.01.2010

Ostrzeżenie: (0%)
-----


Chodzi mi o stworzenie obrazka w ktorym umieszczane sa dane z bazy. Problemem natomiast jest zrobienie tla w zaleznosci od zmiennej.
Mysle, ze wyciaganie z bazy i logowanie moge podarowac. Tak wiec tylko interesujaca czesc kodu.
  1. $imgname = ('foto/button.png');
  2. $my_img = @imagecreatefrompng($imgname);
  3.  
  4. $text_colour = imagecolorallocate( $my_img, 0, 0, 0 );
  5. $prog = imagecolorallocate($my_img, 250, 250, 210 );
  6. if ($status == 'ok'){
  7. $podklad = imagecolorallocate($my_img, 127, 255, 0 );
  8. } elseif ($status == 'oczekuje') {
  9. $podklad = imagecolorallocate($my_img, 176, 196, 222 );
  10. } elseif ($status == 'blad'){
  11. $podklad = imagecolorallocate($my_img, 220, 20, 60 );
  12. }
  13.  
  14. imagestring( $my_img, 10, 5, 80, 'Program:', $text_colour );
  15. imagefilledrectangle ($my_img, 1, 100, 148, 120, $prog);
  16. imagestring( $my_img, 10, 5, 101, $fullname, $text_colour );
  17. imagerectangle ($my_img, 0, 100, 190, 120, $podklad);
  18. imagefilledrectangle ($my_img, 1, 130, 148, 150, $podklad);
  19. imagestring( $my_img, 20, 20, 132, $status, $text_colour );
  20.  
  21. imagesetthickness ( $my_img, 5 );
  22.  
  23. header( "Content-type: image/png" );
  24. imagepng( $my_img );
  25. imagecolordeallocate( $line_color );
  26. imagecolordeallocate( $text_color );
  27. imagecolordeallocate( $background );
  28. imagedestroy( $my_img );


W tym kodzie instrukcja nie wykonuje sie. Tam gdzie powinien byc kolor, jest czarne tlo. Niezaleznie od tego jaka zmienna przyjmuje wartosc. Gdy usuwam instrukcje if i daje tylko jeden kolor, wszystko wyswietla sie jak nalezy. Gdzie zatem jest blad?


#########################################


Zmodyfikowalem kod, ale dalej nie dziala. Co robie nie tak?
Kod
if ($status == 'ok'){
include ('inc/ok.php');
}
elseif ($status == 'oczekuje'){
include ('inc/oczekuje.php');
}
elseif ($status == 'blad'){
include ('inc/blad.php');
}

i przyklad pliku inkludowanego
Kod
<?php
$imgname = ('foto/button.png');    
$my_img = @imagecreatefrompng($imgname);
$prog = imagecolorallocate($my_img, 250, 250, 210 );
$text_colour = imagecolorallocate( $my_img, 0, 128, 128 );
$podklad = imagecolorallocate($my_img, 220, 20, 60 );
imagestring( $my_img, 10, 5, 80, 'Program:', $text_colour );
imagefilledrectangle ($my_img,   1,  100, 148, 120, $prog);
imagestring( $my_img, 10, 5, 101, $fullname, $text_colour );
imagerectangle ($my_img,   0,  100, 190, 120, $podklad);
imagefilledrectangle ($my_img,   1,  122, 148, 142, $podklad);
imagestring( $my_img, 20, 20, 124, $status, $text_colour );

imagesetthickness ( $my_img, 5 );

header( "Content-type: image/png" );
imagepng( $my_img );
imagecolordeallocate( $line_color );
imagecolordeallocate( $text_color );
imagecolordeallocate( $background );
imagedestroy( $my_img );

?>


W tym wypadku wogole nic sie nie wyswietla - po prostu biala strona.

Ten post edytował thek 29.10.2010, 09:50:49
Powód edycji: [thek]: użyj prawidłowego bbcode zanim temat zamknę. Ja poprawiłem Ci 1 fragment. Teraz Twój ruch.
Go to the top of the page
+Quote Post
AlexDeLarge
post 29.10.2010, 10:18:30
Post #2





Grupa: Zarejestrowani
Postów: 85
Pomógł: 14
Dołączył: 14.02.2010

Ostrzeżenie: (0%)
-----


A jaką wartość ma zmienna $status? Podejrzewam, że np. zaczyna się wielką literą, czy coś.

Zdrówka życzę.


--------------------
Java and PHP developer 2007-2014 :)
Go to the top of the page
+Quote Post
c4ash
post 29.10.2010, 11:20:30
Post #3





Grupa: Zarejestrowani
Postów: 73
Pomógł: 9
Dołączył: 14.01.2010

Ostrzeżenie: (0%)
-----


No tak.. glupi blad. Przed instrukcja if dalem strtoupper, po zmianie na duze litery dziala jak nalezy. Dziekuje.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 13.06.2025 - 22:52