PHP skript
PHP skript
Chcel by som sa spýtať že ako by som spravil, že keď mám jeden php skript tak by sa zobrazil ako obrázok(nie ako normálny text)?
Niečo podobné ako http://html.over.cz/html-kod/ip-adresa.php
len namiesto IP adresy by sa zobrazil ten skript.(Adresa toho skriptu je: http://pocasie.webscript.biz)
Ďakujem
Niečo podobné ako http://html.over.cz/html-kod/ip-adresa.php
len namiesto IP adresy by sa zobrazil ten skript.(Adresa toho skriptu je: http://pocasie.webscript.biz)
Ďakujem
-
Gepid
Medium Professional
- Príspevky: 1006
- Registrovaný: 15 júl 2008, 16:54
- Bydlisko: Trnava
- Kontaktovať používateľa:
Pozri sem: http://pabi3.com/blog/praca-s-gd-kniznicou-4-diel-text/
A správne si nastav kódovanie na tej stránke
A správne si nastav kódovanie na tej stránke
Dik, skúšal som to ale keď to takto dám:
tak mi to píše chybu: Parse error: syntax error, unexpected T_STRING in /home/www/webscript.biz/pocasie/obrazkovepocasie.php on line 23
Nemohol by si mi to upraviť tak aby to fungovalo?
Ďakujem
Kód: Vybrať všetko
<?php
// odešle hlavičku prohlížeči kde specifikuje že se jedná o jpeg obrázek.
header ("Content-type:image/jpeg");
// Vytvoří obrázek o rozměrech 75 * 75 px.
$obrazek = ImageCreate(75,75);
// Nastaví barvu obrázku na 0,0,0 (RGB kód který odpovídá #000000).
$barva_cerna = ImageColorAllocate($obrazek,0,0,0);
$barva_bila = Imagecolorallocate ($obrazek,255,255,255);
// vypíše do obrázku písmeno a
imagechar ($obrazek, 5, 25,25,"<?php
class GoogleWeather {
var $lang = "sk"; //Jazyk predpovede počasia
var $country = "Slovakia"; //Krajina kde chcete predpovedať počasie
var $charset = "utf-8"; //Kódovanie počasia
function getWeatherObj($city) {
$city = urlencode($city);
$data = @file_get_contents("http://www.google.com/ig/api?weather=".$city.",".$this->country."&hl=".$this->lang);
if(!$data) {
return false;
}
$data = iconv("ISO-8859-2",$this->charset,$data);
return new SimpleXMLElement($data);
}
function getWeatherInfo($city) {
$weather = array();
$obj = $this->getWeatherObj($city);
if(is_object($obj)) {
$data = $obj->xpath("/xml_api_reply/weather/current_conditions");
if(!empty($data)) {
$weather[] = array(
"condition" => $this->getAttr($data[0]->xpath("condition")),
"temp_f" => $this->getAttr($data[0]->xpath("temp_f")),
"temp_c" => $this->getAttr($data[0]->xpath("temp_c")),
"humidity" => $this->getAttr($data[0]->xpath("humidity")),
"icon" => $this->getAttr($data[0]->xpath("icon")),
"wind_condition" => $this->getAttr($data[0]->xpath("wind_condition"))
);
}
$data = $obj->xpath("/xml_api_reply/weather/forecast_conditions");
if(!empty($data)) {
foreach($data as $value) {
$weather[] = array(
"day_of_week" => $this->getAttr($value->xpath("day_of_week")),
"low" => $this->getAttr($value->xpath("low")),
"high" => $this->getAttr($value->xpath("high")),
"icon" => $this->getAttr($value->xpath("icon")),
"condition" => $this->getAttr($value->xpath("condition"))
);
}
}
}
return $weather;
}
function getAttr($obj) {
$attr = $obj[0]->attributes();
return (string)$attr['data'];
}
}
$gw = new GoogleWeather();
$arrCity = array("Bratislava","Kosice","Poprad","Presov","Trnava","Skalica"); //Mestá ktoré na ktoré chcete mať predpoveď počasia
$content = '<table>';
foreach($arrCity as $city) {
$weather = $gw->getWeatherInfo($city);
//Zobrazenie počasia - ak chcete tak si ju upravte - IBA PRE PROFESIONÁLOV
if(!empty($weather)) {
$content .= '<tr>';
$content .= '<td rowspan="2"><img src="http://www.google.com'.$weather[1]['icon'].'"></td>';
$content .= '<td width="120"><strong>'.$city.'</strong></td>';
$content .= '<td>'.$weather[1]['high'].'°C / '.$weather[1]['low'].'°C</td></font>';
$content .= '</tr><tr>';
$content .= '<td colspan="2">'.$weather[1]['condition'].'</td>';
$content .= '</tr>';
}
}
$content .= '</table>';
echo $content;
?>",$barva_bila);
// Odešle prohlížeči vygenerovaný obrázek.
ImageJpeg ($obrazek);
// Uvolní systémové prostředky.
ImageDestroy ($obrazek);
?>Nemohol by si mi to upraviť tak aby to fungovalo?
Ďakujem
Nie to ja niesom
Keby som potreboval ikonky pre počasie, tak by som si ich spravil(alebo zaplatil za spravenie)
Ak veci stále mi píše to isté, tu je ten upravený súbor:
Nemohli by ste mi to upraviť aby to fungovalo?
Ďakujem
Keby som potreboval ikonky pre počasie, tak by som si ich spravil(alebo zaplatil za spravenie)
Ak veci stále mi píše to isté, tu je ten upravený súbor:
Kód: Vybrať všetko
<?php
// odešle hlavičku prohlížeči kde specifikuje že se jedná o jpeg obrázek.
header ("Content-type:image/jpeg");
// Vytvoří obrázek o rozměrech 75 * 75 px.
$obrazek = ImageCreate(75,75);
// Nastaví barvu obrázku na 0,0,0 (RGB kód který odpovídá #000000).
$barva_cerna = ImageColorAllocate($obrazek,0,0,0);
$barva_bila = Imagecolorallocate ($obrazek,255,255,255);
// vypíše do obrázku písmeno a
imagechar ($obrazek, 5, 25,25,"
class GoogleWeather {
var $lang = "sk"; //Jazyk predpovede počasia
var $country = "Slovakia"; //Krajina kde chcete predpovedať počasie
var $charset = "utf-8"; //Kódovanie počasia
function getWeatherObj($city) {
$city = urlencode($city);
$data = @file_get_contents("http://www.google.com/ig/api?weather=".$city.",".$this->country."&hl=".$this->lang);
if(!$data) {
return false;
}
$data = iconv("ISO-8859-2",$this->charset,$data);
return new SimpleXMLElement($data);
}
function getWeatherInfo($city) {
$weather = array();
$obj = $this->getWeatherObj($city);
if(is_object($obj)) {
$data = $obj->xpath("/xml_api_reply/weather/current_conditions");
if(!empty($data)) {
$weather[] = array(
"condition" => $this->getAttr($data[0]->xpath("condition")),
"temp_f" => $this->getAttr($data[0]->xpath("temp_f")),
"temp_c" => $this->getAttr($data[0]->xpath("temp_c")),
"humidity" => $this->getAttr($data[0]->xpath("humidity")),
"icon" => $this->getAttr($data[0]->xpath("icon")),
"wind_condition" => $this->getAttr($data[0]->xpath("wind_condition"))
);
}
$data = $obj->xpath("/xml_api_reply/weather/forecast_conditions");
if(!empty($data)) {
foreach($data as $value) {
$weather[] = array(
"day_of_week" => $this->getAttr($value->xpath("day_of_week")),
"low" => $this->getAttr($value->xpath("low")),
"high" => $this->getAttr($value->xpath("high")),
"icon" => $this->getAttr($value->xpath("icon")),
"condition" => $this->getAttr($value->xpath("condition"))
);
}
}
}
return $weather;
}
function getAttr($obj) {
$attr = $obj[0]->attributes();
return (string)$attr['data'];
}
}
$gw = new GoogleWeather();
$arrCity = array("Bratislava","Kosice","Poprad","Presov","Trnava","Skalica"); //Mestá ktoré na ktoré chcete mať predpoveď počasia
$content = '<table>';
foreach($arrCity as $city) {
$weather = $gw->getWeatherInfo($city);
//Zobrazenie počasia - ak chcete tak si ju upravte - IBA PRE PROFESIONÁLOV
if(!empty($weather)) {
$content .= '<tr>';
$content .= '<td rowspan="2"><img src="http://www.google.com'.$weather[1]['icon'].'"></td>';
$content .= '<td width="120"><strong>'.$city.'</strong></td>';
$content .= '<td>'.$weather[1]['high'].'°C / '.$weather[1]['low'].'°C</td></font>';
$content .= '</tr><tr>';
$content .= '<td colspan="2">'.$weather[1]['condition'].'</td>';
$content .= '</tr>';
}
}
$content .= '</table>';
echo $content;
",$barva_bila);
// Odešle prohlížeči vygenerovaný obrázek.
ImageJpeg ($obrazek);
// Uvolní systémové prostředky.
ImageDestroy ($obrazek);
?>Ďakujem
-
audiotrack
VIP
- Príspevky: 25958
- Registrovaný: 09 sep 2005, 18:39
- Kontaktovať používateľa:
hmm ty vies co si spravil ?
nemozes vkladat phpcko hoci kam ... idem sa trosku pohrat...potrebujes ten vystup z toho google api do obrazka ?
...
tu to mas ...
je to prasacky napisane ale mas... idem spat...
nezabudni si skopcit aj pisma do tej istej zlozky windows/fonts/times.ttf
ukazka
http://shepdog.sk/pocko2.php
//mensia zmena ...
...
tu to mas ...
Kód: Vybrať všetko
<?php
header ("Content-type:image/jpeg");
$obrazok = imagecreatetruecolor(280,310);
$white = imagecolorallocate($obrazok, 255, 255, 255);
$black = imagecolorallocate($obrazok, 0, 0, 0);
imagefilledrectangle($obrazok, 0, 0, 280, 310, $white);
class GoogleWeather {
var $lang = "sk"; //Jazyk predpovede počasia
var $country = "Slovakia"; //Krajina kde chcete predpovedať počasie
var $charset = "utf-8"; //Kódovanie počasia
function getWeatherObj($city) {
$city = urlencode($city);
$data = @file_get_contents("http://www.google.com/ig/api?weather=".$city.",".$this->country."&hl=".$this->lang);
if(!$data) {
return false;
}
$data = iconv("ISO-8859-2",$this->charset,$data);
return new SimpleXMLElement($data);
}
function getWeatherInfo($city) {
$weather = array();
$obj = $this->getWeatherObj($city);
if(is_object($obj)) {
$data = $obj->xpath("/xml_api_reply/weather/current_conditions");
if(!empty($data)) {
$weather[] = array(
"condition" => $this->getAttr($data[0]->xpath("condition")),
"temp_f" => $this->getAttr($data[0]->xpath("temp_f")),
"temp_c" => $this->getAttr($data[0]->xpath("temp_c")),
"humidity" => $this->getAttr($data[0]->xpath("humidity")),
"icon" => $this->getAttr($data[0]->xpath("icon")),
"wind_condition" => $this->getAttr($data[0]->xpath("wind_condition"))
);
}
$data = $obj->xpath("/xml_api_reply/weather/forecast_conditions");
if(!empty($data)) {
foreach($data as $value) {
$weather[] = array(
"day_of_week" => $this->getAttr($value->xpath("day_of_week")),
"low" => $this->getAttr($value->xpath("low")),
"high" => $this->getAttr($value->xpath("high")),
"icon" => $this->getAttr($value->xpath("icon")),
"condition" => $this->getAttr($value->xpath("condition"))
);
}
}
}
return $weather;
}
function getAttr($obj) {
$attr = $obj[0]->attributes();
return (string)$attr['data'];
}
}
$gw = new GoogleWeather();
$arrCity = array("Bratislava","Kosice","Poprad","Presov","Trnava","Skalica"); //Mestá ktoré na ktoré chcete mať predpoveď počasia
foreach($arrCity as $city) {
$weather = $gw->getWeatherInfo($city);
$ikonka = 'http://www.google.com'.$weather[1]['icon'].'';
if($city == 'Bratislava'){$ikonka_top = '10'; $ikonka_left = '10'; $mesto_top ='25';$mesto_left='60'; $situacia_top='50';$situacia_left='60';$teplota_top='25';$teplota_left='180';}
if($city == 'Kosice'){$ikonka_top = '60'; $ikonka_left = '10'; $mesto_top ='75';$mesto_left='60'; $situacia_top='100';$situacia_left='60';$teplota_top='75';$teplota_left='180';}
if($city == 'Poprad'){$ikonka_top = '110'; $ikonka_left = '10'; $mesto_top ='125';$mesto_left='60'; $situacia_top='150';$situacia_left='60';$teplota_top='125';$teplota_left='180';}
if($city == 'Presov'){$ikonka_top = '160'; $ikonka_left = '10'; $mesto_top ='175';$mesto_left='60'; $situacia_top='200';$situacia_left='60';$teplota_top='175';$teplota_left='180';}
if($city == 'Trnava'){$ikonka_top = '210'; $ikonka_left = '10'; $mesto_top ='225';$mesto_left='60'; $situacia_top='250';$situacia_left='60';$teplota_top='225';$teplota_left='180';}
if($city == 'Skalica'){$ikonka_top = '260'; $ikonka_left = '10'; $mesto_top ='275';$mesto_left='60'; $situacia_top='300';$situacia_left='60';$teplota_top='275';$teplota_left='180';}
$src = imagecreatefromgif($ikonka);
imagecopy($obrazok, $src, $ikonka_left, $ikonka_top, 0, 0, 40, 40);
$font = 'timesbd.ttf';
imagettftext($obrazok, 13, 0, $mesto_left, $mesto_top, $black, $font, $city);
$situacia = ''.$weather[1]['condition'].'';
$font = 'times.ttf';
imagettftext($obrazok, 11, 0, $situacia_left, $situacia_top, $black, $font, $situacia);
$font = 'times.ttf';
$teplota = ''.$weather[1]['high'].'°C / '.$weather[1]['low'].'°C';
imagettftext($obrazok, 13, 0, $teplota_left, $teplota_top, $black, $font, $teplota);
}
ImageJpeg ($obrazok);
ImageDestroy ($obrazok);
?>
nezabudni si skopcit aj pisma do tej istej zlozky windows/fonts/times.ttf
ukazka
http://shepdog.sk/pocko2.php
//mensia zmena ...