Voting

: three minus zero?
(Example: nine)

The Note You're Voting On

JohnBrook at pobox dot com
19 years ago
Also, here is the same formula presented in a somewhat more human-readable way, if you'd rather:

<?php
$MB
= Pow(1024,2); // number of bytes in 1M
$K64 = Pow(2,16); // number of bytes in 64K
$TWEAKFACTOR = 1.8; // Or whatever works for you
$memoryNeeded = round( ( $imageInfo[0] * $imageInfo[1]
*
$imageInfo['bits']
*
$imageInfo['channels'] / 8
+ $K64
) * $TWEAKFACTOR
);
$memoryHave = memory_get_usage();
$memoryLimitMB = (integer) ini_get('memory_limit');
$memoryLimit = $memoryLimit * $MB;

if (
function_exists('memory_get_usage')
&&
$memoryHave + $memoryNeeded > $memoryLimit
) {
$newLimit = $memoryLimitMB + ceil( ( $memoryHave
+ $memoryNeeded
- $memoryLimit
) / $MB
);
ini_set( 'memory_limit', $newLimit . 'M' );
}
?>

<< Back to user notes page

To Top