Save Image
Ein Bild wird dynamisch erzeugt und in einem Grafikformat im aktuellen Verzeichnis gespeichert, sofern Schreibrechte vorhanden sind.
Bild sichern: Beispiel ansehen
Code:
<?php #Grafikformat festlegen $xmax=500; $ymax=300; $img = @imagecreatetruecolor($xmax,$ymax) or die ("Kann kein neues Bild erzeugen"); #Farben zuweisen $black = imagecolorallocate($img, 0, 0, 0); $white = imagecolorallocate($img, 255, 255, 255); $red = imagecolorallocate($img, 255, 0, 0); $green = imagecolorallocate($img, 0, 255, 0); $blue = imagecolorallocate($img, 0, 0, 255); $yellow= imagecolorallocate($img, 255,255, 0); #Grafik mit Hintergrundfarbe füllen imagefill($img, 0, 0, $white); #x-Achse zeichen imageline($img,10,$ymax/2,$xmax-10,$ymax/2,$black); #y-Achse zeichnen imageline($img,$xmax/2,10,$xmax/2,$ymax-10,$black); #Funktion y=70*sin(x) for ($x=10;$x<=$xmax-10;$x++){ #Koordinatentransformation $xr=$x-$xmax/2; $y=70*sin($xr/20); $y=-$y+$ymax/2 imagesetpixel($img,$x,$y,$red); } #Speichern im aktuellen Verzeichnis imagejpeg($img, "sinus.jpg", 100); #Für die Browseranzeige header("Content-type: image/jpeg"); #Anzeigen imagejpeg($img); #Löschen des Image-Objektes imagedestroy($img); ?>