私は150x150のセルを持つテーブルを持っています。各テーブルには色付きの背景と小さなイメージ/シンボルがあります。さらに、各セルは0以上のボーダーも設定できます。ユーザーは、枠線を変更して追加し、セルの色とセルを変更することができます。これはjqueryを使用してすべてうまく動作し、それは単純なhtmlテーブルです。メモリの使用状況を確認します
ユーザーエクスペリエンスの終わりに、私はダウンロードするためにこのテーブルのpdfを作成しています。これは大きな仕事であり、しばらく時間がかかりますが、今はこれが私の主な関心事ではありません。 jQueryはテーブルデータを配列に集め、phpに送信してgdライブラリを使って画像として再作成します。
各セルでは、大きな画像に正しい色の矩形を描き、シンボル画像をロードして大きな画像にリサンプリングし、境界線を描きシンボル画像をイメージ化していましたが、1分かかりました。私は小さな色の矩形にイメージを置くように戦略を変更し、素早く再度使用するために配列にキャッシュしました。それは私の時間をスピードアップし、30秒に短縮しましたが、今は記憶が枯渇しています。
テーブルを50個のセルブロックに分割してページに収まるようにし、各ブロックを画像にしてディスクに保存し、次の画像を作成して保存します.GD画像が破棄されるたびに、その後、すべてのブロックがpdfに挿入されます。
だからこそ、私の質問は、メモリをどこで使用しているのか分かりやすくするために、私はそれを解放しようとしますか?私は以下の問題の原因と思われる主な機能を掲載しました。私のテストでは、25個の異なるシンボル/カラーの画像(25pxX25px)があります。これらの画像は配列にキャッシュされています。
私は十分な情報を提供し、私の問題は十分明確であることを望みます。
は(あなたがまだの場合は)私は、これらは非常に貴重なツールになりますように良いIDEとデバッガを取得することにより開始する、お時間 トッド
//make one "block" of stitches returns image file name.
//function makeStitchChartBlock($img, $startX, $startY, $endX, $endY, $caption, $brand){
function makeStitchChartBlock($stitchChartArray, $startX, $startY, $endX, $endY, $caption, $brand,$blockNumber){
global $threadColours;
$stitchCache=array();
$saveTo = 'result'.$blockNumber.'.jpeg';
// calculate size of block
$numRows=($endY-$startY);
$numColumns=($endX-$startX);
$heightOfBlock = $numRows*SYMBOL_SIZE; //in pixels --- used to determine size of image to make for block
$widthOfBlock = $numColumns*SYMBOL_SIZE; //in pixels
//----plus any extra for captions grid lines
$heightOfBlock += (($endY-$startY)+1); //each stitch has a grid line before it and the last one also has on after it
$widthOfBlock += (($endX-$startX)+1);
// create image size of block to put stitches in
$newBlockImage = imagecreatetruecolor($widthOfBlock,$heightOfBlock);
$backStitchColor = imagecolorallocate($newBlockImage, 0, 0, 0);
// insert caption????
//draw grid lines
//$newBlockImage = addGridToImage($newBlockImage);
//keep track of where to start next cell top left
$blockX=0;
$blockY=0;
for($y = $startY; $y < $endY; $y++){ //for each pixel in height, move down 1 "row" each iteration
//echo "<tr>";
for($x = $startX; $x < $endX; $x++){ // "draws" a row (for each y pixel)
//rgb(75, 90, 60)
//x and y are column and row #'s
list($r, $g, $b) = getRGBs($stitchChartArray[$y][$x][0]); //get the rgb values for the cell
$stitchColor = imagecolorallocate($newBlockImage, $r, $g, $b);
//calculate x & y start positons
$stitchStartX=($blockX*SYMBOL_SIZE)+$blockX+1; //account for each previous stitch and the grid line, then add one for new grid line
$stitchStartY=($blockY*SYMBOL_SIZE)+$blockY+1;
$stitchEndX=$stitchStartX+(SYMBOL_SIZE);
$stitchEndY=$stitchStartY+(SYMBOL_SIZE);
/* make a symbol cell image with/without color and save it in the cache */
if(!isset($stitchCache[$r][$g][$b]))
{
//create new image
$stitchCache[$r][$g][$b] = imagecreatetruecolor(SYMBOL_SIZE,SYMBOL_SIZE);
$stitchCacheColor = imagecolorallocate($stitchCache[$r][$g][$b], $r, $g, $b);
//draw colored rectangle
imagefilledrectangle($stitchCache[$r][$g][$b], 0, 0, SYMBOL_SIZE-1, SYMBOL_SIZE-1, $stitchCacheColor);
//add the symbol
$symbolFile=$stitchChartArray[$y][$x][1];
if($symbolFile){
$symbolImage = imagecreatefrompng($symbolFile);
imagecopyresampled ($stitchCache[$r][$g][$b],$symbolImage,0,0,0,0,SYMBOL_SIZE-1,SYMBOL_SIZE-1,imagesx($symbolImage), imagesy($symbolImage));
imagedestroy($symbolImage);
}
}
//add image from cache to the block image
imagecopyresampled ($newBlockImage,$stitchCache[$r][$g][$b],$stitchStartX, $stitchStartY,0,0,SYMBOL_SIZE,SYMBOL_SIZE,SYMBOL_SIZE,SYMBOL_SIZE);
//add the backstitch lines(borders)
if($stitchChartArray[$y][$x][2]>1) //top
{
imagefilledrectangle($newBlockImage, $stitchStartX, $stitchStartY, $stitchEndX, $stitchStartY+1, $backStitchColor);
}
if($stitchChartArray[$y][$x][3]>1) //right
{
imagefilledrectangle($newBlockImage, $stitchEndX-1, $stitchStartY, $stitchEndX, $stitchEndY, $backStitchColor);
}
if($stitchChartArray[$y][$x][4]>1) //bottom
{
imagefilledrectangle($newBlockImage, $stitchStartX, $stitchEndY-1, $stitchEndX, $stitchEndY, $backStitchColor);
}
if($stitchChartArray[$y][$x][5]>1) //left
{
imagefilledrectangle($newBlockImage, $stitchStartX, $stitchStartY, $stitchStartX+1, $stitchEndY, $backStitchColor);
}
//advance x position
$blockX++;
}
//advance y position
//reset x
$blockX=0;
$blockY++;
}
imagejpeg($newBlockImage, $saveTo);
imagedestroy($newBlockImage);
//dump stitch cache
foreach($stitchCache as $r)
{
foreach($r as $g)
{
foreach($g as $b=>$data)
{
imagedestroy($data);
}
}
}
return $saveTo;
}
これは非常に良いスタートになるでしょう。そして、グローバルな提案に感謝します...正式に注目され、変更されました。 – maddogandnoriko
あなたの助けを借りて私は問題を見つけました。私は大規模な配列を$ POST経由でページに渡しています。そして、メモリはトップから13124128です。$ _POST ['stitchChart'] varをダンプしてメモリを解放することはできますか? – maddogandnoriko
はい、そうすることができます。または、そのスクリプトのメモリー制限を増やすこともできます。なぜ$ _POSTがそれほど大きいのかを見たいかもしれません。これはあなたが投稿しているデータの多くです。 – liquorvicar