Hoi,
Ben momenteel bezig met een klein tussen project en ik kom nu op een probleem aan, ik wil van alle images in een map 1 image maken, alleen heb ik dat nu alleen is het erg slechte kwaliteit:
Afbeelding niet beschikbaarDe bron kon niet worden geladen (i.imgur.com).Bron openen ↗
Weet iemand hoe dit kan?
Code:
Codeblok (voorbeeld.php):
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
class Spread {
public $imagePath;
private $imagesInfo, $width, $height;
public function __construct($imagesPath) {
$this->imagesPath = $imagesPath;
$this->images = glob($imagesPath . "*.jpg");
}
public function createSpread() {
$imagesInfo = array(totalWidth => 0, highestHeight => 0);
$index = 0;
foreach ($this->images as $image) {
list($width, $height) = getimagesize($image);
$imagesInfo[$index][width] = $width;
$imagesInfo[$index][height] = $height;
$index++;
$imagesInfo[totalWidth] += $width;
$imagesInfo[highestHeight] = ($height > $imagesInfo[highestHeight] ? $height : $imagesInfo[highestHeight]);
}
$index = 0;
$prev = $imagesInfo[0][width];
$coords = array();
$dest = imagecreatetruecolor($imagesInfo[totalWidth], $imagesInfo[highestHeight]);
foreach ($this->images as $image) {
$src = imagecreatefromjpeg($image);
list($width, $height) = getimagesize($image);
imagecopy($dest, $src, (isset($imagesInfo[($index-1)]) == 1 ? ($index == 1 ? $imagesInfo[0][width] : ($imagesInfo[$index][width] + $prev)) : 0), 0, 0, 0, $width, $height);
$prev = (isset($imagesInfo[($index-1)]) == 1 ? ($imagesInfo[0][width] + $prev): 0);
$index++;
}
return $dest;
}
}
Ben momenteel bezig met een klein tussen project en ik kom nu op een probleem aan, ik wil van alle images in een map 1 image maken, alleen heb ik dat nu alleen is het erg slechte kwaliteit:
Afbeelding niet beschikbaarDe bron kon niet worden geladen (i.imgur.com).Bron openen ↗Weet iemand hoe dit kan?
Code:
Codeblok (voorbeeld.php):
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
class Spread {
public $imagePath;
private $imagesInfo, $width, $height;
public function __construct($imagesPath) {
$this->imagesPath = $imagesPath;
$this->images = glob($imagesPath . "*.jpg");
}
public function createSpread() {
$imagesInfo = array(totalWidth => 0, highestHeight => 0);
$index = 0;
foreach ($this->images as $image) {
list($width, $height) = getimagesize($image);
$imagesInfo[$index][width] = $width;
$imagesInfo[$index][height] = $height;
$index++;
$imagesInfo[totalWidth] += $width;
$imagesInfo[highestHeight] = ($height > $imagesInfo[highestHeight] ? $height : $imagesInfo[highestHeight]);
}
$index = 0;
$prev = $imagesInfo[0][width];
$coords = array();
$dest = imagecreatetruecolor($imagesInfo[totalWidth], $imagesInfo[highestHeight]);
foreach ($this->images as $image) {
$src = imagecreatefromjpeg($image);
list($width, $height) = getimagesize($image);
imagecopy($dest, $src, (isset($imagesInfo[($index-1)]) == 1 ? ($index == 1 ? $imagesInfo[0][width] : ($imagesInfo[$index][width] + $prev)) : 0), 0, 0, 0, $width, $height);
$prev = (isset($imagesInfo[($index-1)]) == 1 ? ($imagesInfo[0][width] + $prev): 0);
$index++;
}
return $dest;
}
}
49: