Thread (PHP) Warum kein Output bei imagecopyresampled? (17 answers)
Opened by Pida at 2007-08-10 13:24

Pida
 2007-08-12 16:42
#98003 #98003
User since
2006-06-09
52 Artikel
BenutzerIn
[default_avatar]
So, hier nun die Lösung des Problems.

Gruß, Pida

Code: (dl )
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
// Max. Hoehe und Breite
$width = 200;
$height = 200;

// Quelle angeben
$src_file = imagecreatefromjpeg("http://***/images/test1.jpg") or die ("no such pic"); // hier darf als Pfad nur eine URL stehen

// Neue Masse ermitteln
$size_orig = getimagesize("http://***/images/test1.jpg") or die ("no size information"); // getimagesize($src_file) funktioniert nicht


$width_orig = $size_orig[0] or die ("size");
$height_orig = $size_orig[1] or die ("size");
$ratio_orig = $width_orig/$height_orig or die ("ratio");

if (($width_orig/$height_orig) > $ratio_orig) {
$width = $height_orig*$ratio_orig;
} else {
$height = $width_orig/$ratio_orig;
}

// Neues Bild erstellen
$dest_file = imagecreatetruecolor($width, $height) or die ("no new pic");

// Neues Bild füllen
imagecopyresampled($dest_file, $src_file, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig) or die ("icr");
imageinterlace($dest_file, 1) or die ("interlace"); // Hier muss ein zweites Argument übergeben werden:
// 1 = progressive Darstellung ein, 0 = progressive Darstellung aus

// Output
$dest_name = "images/test.jpg";
imagejpeg($dest_file, $dest_name, 80) or die ("output"); // hier darf an Stelle von $dest_name wohl keinerlei Pfad stehen

View full thread (PHP) Warum kein Output bei imagecopyresampled?