PHP-Snippets
 php::MySQL (0)
 php::Image (4)
   » Bild - Boxskalierung
   » Hex-Farbcode -> Farb-Array
   » Farb - Aufheller
   » Farb - Abdunkler
 php::Sonstiges (4)
   » Einfache Template-Funktion
   » Simple HTTP-Post Funktion
   » Simple HTTP-Get Funktion
   » zwischen()-Funktion
 php::Spezielles (2)
   » Zeichenvorkommisse prüfen
   » Array mischen (seeded)
Snippet: Bild - Boxskalierung

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
<?php
function dfx_imgscale($pic_width,$pic_height,$boxsize,$mode "border")
{
    
// Modus 1: Mit Rändern
    // Modus 2: Ohne Ränder
    // Zwischen den Moeglichkeiten switchen
    
if($pic_width $pic_height// Querformat
    
{
        if(
$mode == "border")
        {
            
$ratio $pic_height/$pic_width;
            
$result['width'] = $boxsize;
            
$result['height'] = $boxsize*$ratio;
            
$result['x'] = 0;
            
$result['y'] = ($boxsize-$result['height'])/2;
        }
        else
        {
            
$ratio $pic_width/$pic_height;
            
$result['width'] = $boxsize*$ratio;
            
$result['height'] = $boxsize;
            
$result['x'] = -(($result['width']-$boxsize)/2);
            
$result['y'] = 0;
        }
        
    }
    if(
$pic_width $pic_height// Hochformat
    
{
        if(
$mode == "border")
        {
            
$ratio $pic_width/$pic_height;
            
$result['width'] = $boxsize*$ratio;
            
$result['height'] = $boxsize;
            
$result['x'] = ($boxsize-$result['width'])/2;
            
$result['y'] = 0;
        }
        else
        {
            
$ratio $pic_height/$pic_width;
            
$result['width'] = $boxsize;
            
$result['height'] = $boxsize*$ratio;
            
$result['x'] = 0;
            
$result['y'] = -(($result['height']-$boxsize)/2);
        }
    }
    if(
$pic_width == $pic_height// Quadratisch
    
{
        
$result['width'] = $boxsize;
        
$result['height'] = $boxsize;
        
$result['x'] = 0;
        
$result['y'] = 0;
    }
    
    
// Rückgabewerte runden
    
$result['width'] = floor($result['width']);
    
$result['height'] = floor($result['height']);
    
    return 
$result// Rückgabe: Array mit Höhe und Breite
}
?>