heyho
ich hab nen kleines problem mit meinem code.
ich brauch tiles von einem sehr großen bild (12k mal 9k pixel)
dafür hab ich nen kleines phpscript geschrieben, was mir das ganze ding zerhackt.
script:
das ganze läuft ohne fehler durch, allerdings sind die tiles die rauskommen nicht passend. das input bild ist 12k hoch und 9k breit. die tiles gehen von oben nach unten über das ganze bild, aber nach rechts nur bis ca. 7k pixel.
woran liegt das? hab ich nen fehler drin, den ich seit ewigkeiten nicht sehe oder gibts ein limit von php her? eingesetzt wird hier php5.2.9 cli unter win32
ich hab nen kleines problem mit meinem code.
ich brauch tiles von einem sehr großen bild (12k mal 9k pixel)
dafür hab ich nen kleines phpscript geschrieben, was mir das ganze ding zerhackt.
script:
PHP:
<?php
class prepareImage {
private $outdir;
private $image;
private $tileSize = 100;
public function __construct() {
error_reporting(E_ALL);
ini_set("display_errors",true);
ini_set("memory_limit","2048M");
$this->outdir = dirname(__FILE__) . "/out";
$this->checkDirs();
$this->loadFile();
}
private function loadFile() {
if (!file_exists(dirname(__FILE__) . "/input.png")) die();
$this->image = imagecreatefrompng(dirname(__FILE__) . "/input.png");
imagealphablending($this->image, true);
imagesavealpha($this->image, true);
$this->size = getimagesize(dirname(__FILE__) . "/input.png");
$sizes = array(10,15,25,50,75,100);
for ($i = 0; $i < count($sizes);$i++) {
echo "\n\nround {$i}\n";
echo "tiles: ";
mkdir(dirname(__FILE__) . "/out/size_{$i}");
$this->resize($sizes[$i]);
$this->splitImage($i);
$this->ImageDestroy();
}
}
private function checkDirs() {
if (!is_writeable($this->outdir)) die("outdir not writeable");
}
private function splitImage($i) {
$y = imagesy($this->imageNew);
$x = imagesx($this->imageNew);
$tilesV = bcdiv($x,100)+1;
$tilesH = bcdiv($y,100)+1;
for ($y = 1; $y < $tilesH; $y++) {
for($x = 1; $x < $tilesV;$x++) {
echo ".";
flush();
$tile = imagecreatetruecolor(100, 100);
imagecopy($tile, $this->imageNew, 0, 0, ($x*100)-100, ($y*100)-100, 100, 100);
imagepng($tile,$this->outdir . "/size_{$i}/{$x}_{$y}.png");
imagedestroy($tile);
}
}
}
public function resize($percentage) {
$ow = imagesx( $this->image );
$oh = imagesy( $this->image );
$mw = floor($ow / 100 * $percentage);
#$mh = floor($oh / 100 * $percentage);
if( $ow > $mw || $oh > $mh ) {
if( $ow > $oh ) {
$tnw = $mw;
$tnh = $tnw * $oh / $ow;
} else {
$tnh = $mh;
$tnw = $tnh * $ow / $oh;
}
} else {
$tnw = $ow;
$tnh = $oh;
}
$this->imageNew = imagecreatetruecolor( $tnw, $tnh );
imagecopyresampled( $this->imageNew, $this->image, 0, 0, 0, 0, $tnw, $tnh, $ow, $oh );
}
public function ImageDestroy() {
imagedestroy($this->imageNew);
}
}
new prepareImage();
?>
das ganze läuft ohne fehler durch, allerdings sind die tiles die rauskommen nicht passend. das input bild ist 12k hoch und 9k breit. die tiles gehen von oben nach unten über das ganze bild, aber nach rechts nur bis ca. 7k pixel.
woran liegt das? hab ich nen fehler drin, den ich seit ewigkeiten nicht sehe oder gibts ein limit von php her? eingesetzt wird hier php5.2.9 cli unter win32
Code:
<?php
class prepareImage {
private $outdir;
private $image;
private $tileSize = 100;
public function __construct() {
error_reporting(E_ALL);
ini_set("display_errors",true);
ini_set("memory_limit","2048M");
$this->outdir = dirname(__FILE__) . "/out";
$this->checkDirs();
$this->loadFile();
}
private function loadFile() {
if (!file_exists(dirname(__FILE__) . "/input.png")) die();
$this->image = imagecreatefrompng(dirname(__FILE__) . "/input.png");
imagealphablending($this->image, true);
imagesavealpha($this->image, true);
$this->size = getimagesize(dirname(__FILE__) . "/input.png");
$sizes = array(10,15,25,50,75,100);
for ($i = 0; $i < count($sizes);$i++) {
echo "\n\nround {$i}\n";
echo "tiles: ";
mkdir(dirname(__FILE__) . "/out/size_{$i}");
$this->resize($sizes[$i]);
$this->splitImage($i);
$this->ImageDestroy();
}
}
private function checkDirs() {
if (!is_writeable($this->outdir)) die("outdir not writeable");
}
private function splitImage($i) {
$y = imagesy($this->imageNew);
$x = imagesx($this->imageNew);
$tilesV = bcdiv($x,100)+1;
$tilesH = bcdiv($y,100)+1;
for ($y = 1; $y < $tilesH; $y++) {
for($x = 1; $x < $tilesV;$x++) {
echo ".";
flush();
$tile = imagecreatetruecolor(100, 100);
imagecopy($tile, $this->imageNew, 0, 0, ($x*100)-100, ($y*100)-100, 100, 100);
imagepng($tile,$this->outdir . "/size_{$i}/{$x}_{$y}.png");
imagedestroy($tile);
}
}
}
public function resize($percentage) {
$ow = imagesx( $this->image );
$oh = imagesy( $this->image );
$mw = floor($ow / 100 * $percentage);
#$mh = floor($oh / 100 * $percentage);
if( $ow > $mw || $oh > $mh ) {
if( $ow > $oh ) {
$tnw = $mw;
$tnh = $tnw * $oh / $ow;
} else {
$tnh = $mh;
$tnw = $tnh * $ow / $oh;
}
} else {
$tnw = $ow;
$tnh = $oh;
}
$this->imageNew = imagecreatetruecolor( $tnw, $tnh );
imagecopyresampled( $this->imageNew, $this->image, 0, 0, 0, 0, $tnw, $tnh, $ow, $oh );
}
public function ImageDestroy() {
imagedestroy($this->imageNew);
}
}
new prepareImage();
?>
Zuletzt bearbeitet: