Teil von  SELFPHP   Teil von  Code Snippets / PHP / Images
  +++ SELFPHP CronJob-Service :: Jetzt auch als Professional-Version verfügbar! +++

:: Anbieterverzeichnis ::

Globale Branchen

Informieren Sie sich über ausgewählte Unternehmen im Anbieterverzeichnis von SELFPHP  

 

:: SELFPHP Forum ::

Fragen rund um die Themen PHP? In über 120.000 Beiträgen finden Sie sicher die passende Antwort!  

 

:: Newsletter ::

Abonnieren Sie hier den kostenlosen SELFPHP Newsletter!

Vorname: 
Name:
E-Mail:
 
 

:: Qozido ::

Die Bilderverwaltung mit Logbuch für Taucher und Schnorchler.   

 
 
Grafische Fortschrittsanzeige mit PHP erstellen





Beispielaufgabe

Nachfolgend stellen wir Ihnen eine Funktion vor, mit der Sie grafische Fortschrittsanzeigen komfortabel erstellen können. Gerade wenn es darum geht eine Fortschrittsanzeige auf mehreren Seiten (z.B. bei einer Umfrage) anzuzeigen, kann diese Fortschrittsanzeige visuell dem User anzeigen, wieviel Prozent der Umfrage bereits beantwortet wurde.

Die Funktion ist so konzipiert, dass Sie neben der Breite und Höhe für die Fortschrittsanzeige auch noch folgende Parameter einstellen können:
  • die Rahmenfarbe der Grafik
  • die Farbe der Aufteilungslininien - alle 10% wird eine gestrichelte vertikale Linie angezeigt
  • die Hintergrundfarbe
  • eine True-Type Schrift - hier muss der Pfad zu der TTF-Datei angegeben werden
  • die Schriftgröße

Nachfolgend sehen Sie so eine generierte Fortschrittsanzeige:




progressbar-test.php

Nachfolgend sehen Sie den Zugriff auf die Funktion.

<img src="progressbar.php?progress=7"/>





progressbar.php

Hier sehen Sie noch die vollständige Funktion für die Erzeugung der Fortschrittsanzeige.

<?php

/**
 * Fortschrittsanzeige
 * 
 * @author SELFPHP OHG
 * @copyright 2009, SELFPHP OHG
 * @license BSD License
 * @link http://www.selfphp.de 
 * 
 */

function hexdecColor$color ){
    
    
$colorRGB['r'] = hexdecsubstr$color0) ); 
    
$colorRGB['g'] = hexdecsubstr$color2) ); 
    
$colorRGB['b'] = hexdecsubstr$color4) );
    
    return 
$colorRGB;

}

function 
createProgressBar($environment$step 0){
    
    if( 
$step || $step 10 )
        
$step 0;
        
    
$lineWidth $environment['width'] / 10;
    
    
$progress $environment['width'] - ( $step $lineWidth );
    
    
$status $step 10;
    
    
$im imagecreatetruecolor($environment['width'], $environment['height']);

    
$color hexdecColor($environment['backgroundColor']);
    
$imBackgroundColor imagecolorallocate($im$color['r'], $color['g'], $color['b']);

    
$color hexdecColor($environment['borderColor']);
    
$imBorderColor imagecolorallocate($im$color['r'], $color['g'], $color['b']);

    
// Set the background to be white
    
imagefilledrectangle($im00$environment['width'], $environment['height'], $imBackgroundColor);

    
// Set the line thickness to 5
    
imagesetthickness($im1);

    
// Draw the rectangle
    
imagerectangle($im00$environment['width'] - 1$environment['height'] - 1$imBorderColor);


    
$color hexdecColor($environment['lineColor']);
    
$imLineColor imagecolorallocate($im$color['r'], $color['g'], $color['b']); 

    
imagefilledrectangle($im03$environment['width'] - $progress$environment['height'] - 4$imBorderColor);

    for (
$i 1$i 10$i++ ){
        
imagedashedline $im $lineWidth $i $lineWidth $i 60 $imLineColor );
    }

    
$text $status '%';

    
// Benötigte Schriftgröße kalkulieren
    
$fontsize imageftbbox($environment['fontsize'], 0$environment['font'], $text);
    
$x $fontsize[0] + (imagesx($im) / 2) - ($fontsize[4] / 2) - 5;
    
$y $fontsize[1] + (imagesy($im) / 2) - ($fontsize[5] / 2) - 5;

    
$black imagecolorallocate($im000);
    
imagettftext($im$environment['fontsize'], 0$x18$black$environment['font'], $text);

    
// Output image to the browser
    
header('Content-Type: image/png');

    
imagepng($im);
    
imagedestroy($im);
    
}

$environment['width'] = 326;
$environment['height'] = 25;
$environment['lineColor'] = "ffd0b2";
$environment['borderColor'] = "fe934f";
$environment['backgroundColor'] = "fff3eb";
$environment['font'] = 'bgothl.ttf';
$environment['fontsize'] = 14;

if (isset(
$_GET['progress']))
    
createProgressBar($environment$_GET['progress']);

?>





Download
progessbar.zip






 




:: Premium-Partner ::

Webhosting/Serverlösungen


Premium-Partner LeaseWeb Germany GmbH
Premium-Partner MECO Systemhaus GmbH & Co. KG
Premium-Partner PSW GROUP GmbH & Co. KG
Premium-Partner BPI-Systeme
Premium-Partner Pixel X
Premium-Partner
 

:: SELFPHP Sponsoren ::


DM Solutions
Microsoft Deutschland GmbH
Sedo - Bei uns wird PHP großgeschrieben
hostfactory.ch - OptimaNet Schweiz AG
ZEND - The PHP Company
Kaspersky Labs
HighText iBusiness
SELFPHP Sponsoren
 

Qozido


© 2001-2013 E-Mail SELFPHP OHG, info@selfphp.deImpressumKontakt