Autor Zpráva
Fisak
Profil
Dobrý den. POtřeboval bych poradit s tvořením jednoho velkého obrázku. Chci si udělat mapku.. každá souřadnice má svojí texturu.. každá textura má 50x50px a mapa má celkem 500x500px ...a potřebuju to vše spojit a načítat to pomocí ajaxu každou vteřinu.. ovšem můj kod je už tak dost pomalý.. nemá někdo lepší řešení než-li já?
$filename = $hodnoty['text'];
list($width, $height) = getimagesize($filename);
$new_width = "50";
$new_height = "50";

// Resample
$image_p = @imagecreatetruecolor(500, 500) or die('Cannot Initialize new GD image stream');
$image = imagecreatefromjpeg($filename);
//1 line
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagecopyresampled($image_p, $image, 50, 0, 0, 0, $new_width, $new_height, $width, $height);
imagecopyresampled($image_p, $image, 100, 0, 0, 0, $new_width, $new_height, $width, $height);
imagecopyresampled($image_p, $image, 150, 0, 0, 0, $new_width, $new_height, $width, $height);
imagecopyresampled($image_p, $image, 200, 0, 0, 0, $new_width, $new_height, $width, $height);
imagecopyresampled($image_p, $image, 250, 0, 0, 0, $new_width, $new_height, $width, $height);
imagecopyresampled($image_p, $image, 300, 0, 0, 0, $new_width, $new_height, $width, $height);
imagecopyresampled($image_p, $image, 350, 0, 0, 0, $new_width, $new_height, $width, $height);
imagecopyresampled($image_p, $image, 400, 0, 0, 0, $new_width, $new_height, $width, $height);
imagecopyresampled($image_p, $image, 450, 0, 0, 0, $new_width, $new_height, $width, $height);

//2 line
imagecopyresampled($image_p, $image, 0, 50, 0, 0, $new_width, $new_height, $width, $height);
imagecopyresampled($image_p, $image, 50, 50, 0, 0, $new_width, $new_height, $width, $height);
imagecopyresampled($image_p, $image, 100, 50, 0, 0, $new_width, $new_height, $width, $height);
imagecopyresampled($image_p, $image, 150, 50, 0, 0, $new_width, $new_height, $width, $height);
imagecopyresampled($image_p, $image, 200, 50, 0, 0, $new_width, $new_height, $width, $height);
imagecopyresampled($image_p, $image, 250, 50, 0, 0, $new_width, $new_height, $width, $height);
imagecopyresampled($image_p, $image, 300, 50, 0, 0, $new_width, $new_height, $width, $height);
imagecopyresampled($image_p, $image, 350, 50, 0, 0, $new_width, $new_height, $width, $height);
imagecopyresampled($image_p, $image, 400, 50, 0, 0, $new_width, $new_height, $width, $height);
imagecopyresampled($image_p, $image, 450, 50, 0, 0, $new_width, $new_height, $width, $height);

//3 line
imagecopyresampled($image_p, $image, 0, 100, 0, 0, $new_width, $new_height, $width, $height);
imagecopyresampled($image_p, $image, 50, 100, 0, 0, $new_width, $new_height, $width, $height);
imagecopyresampled($image_p, $image, 100, 100, 0, 0, $new_width, $new_height, $width, $height);
imagecopyresampled($image_p, $image, 150, 100, 0, 0, $new_width, $new_height, $width, $height);
imagecopyresampled($image_p, $image, 200, 100, 0, 0, $new_width, $new_height, $width, $height);
imagecopyresampled($image_p, $image, 250, 100, 0, 0, $new_width, $new_height, $width, $height);
imagecopyresampled($image_p, $image, 300, 100, 0, 0, $new_width, $new_height, $width, $height);
imagecopyresampled($image_p, $image, 350, 100, 0, 0, $new_width, $new_height, $width, $height);
imagecopyresampled($image_p, $image, 400, 100, 0, 0, $new_width, $new_height, $width, $height);
imagecopyresampled($image_p, $image, 450, 100, 0, 0, $new_width, $new_height, $width, $height);

// moderátorem smazány zbylé řádky

//.. ještě je zde 10 line ale kod je příliš dlouhý 
// Output 
header('Content-Type: image/jpeg');
imagejpeg($image_p, null, 100); 
Alphard
Profil
Ty hromady imagecopyresampled() lze nahradit cyklem, ale výkon to nevyřeší.
Co třeba spojit to až u klienta, třeba to nacpat do tabulky, absolutně napozicovat a tak.
Fisak
Profil
Alphard:
No takhle jsem to právě řešil dříve.. Ale chtěl jsem z toho mít jeden celkový obrázek a vždy podle pozice (souřadnic x, y) by se našetl pomocí ajau nový obrázek... chtěl jsem to udělat hlavně kvůli ajaxu aby se mi nenačítalo 100 obrázků každou vteřinu ale jen jeden velký obrázek každou vteřinu..
Alphard
Profil
A to je 100 unikátních obrázků?
Nemůžete mít jeden velký, který obsahuje vše po jednom vzorku a posouvat ho?
A k ajaxu obecně, opravdu to musí být každou sekundu?
Alphard
Profil
Nemůžete mít jeden velký, který obsahuje vše po jednom vzorku a posouvat ho?
Pokud by tohle nebylo srozumitelné, myslím tím tohle

(zdůrazňuji, že je to jediný obrázek a zobrazena je pouze část, doufám, že to google nesmaže).

Ještě jsem si všiml tohoto:
imagejpeg($image_p, null, 100); 
Nemá téměř žádný smysl nastavovat kvalitu jpeg na 100. V blízkosti této hranice extrémně roste datová velikost, naopak kvalita neznatelně.
Fisak
Profil
Alphard:
Mno vím jak to myslíte ale tech textur je tam obrovské množství (voda, tráva, cesta, hradba, cesto-tráva.. a různé další jiné kombinace) prostě tech textur je hrozivě moc..a teoreticky to nemusím načítat každou vteřinu... stačí když se mi to načte jednou plynule...
Alphard
Profil
Obrovské množství, cca 5, a nějaké další kombinace :-)
Nemůžete nám ukázat příklad obrázku, který sestavujete?

a teoreticky to nemusím načítat každou vteřinu... stačí když se mi to načte jednou plynule...
Tomu jednou plynule nerozumím, ale když budete mít všechny vzory v jednom obrázku načtené na začátku, tak pak už bude stačit ajaxem načítat jen mapu souřadnic, co kde zobrazit.

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0