本文整理汇总了PHP中Pow函数的典型用法代码示例。如果您正苦于以下问题:PHP Pow函数的具体用法?PHP Pow怎么用?PHP Pow使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Pow函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct($file)
{
// BOF - Zappo - ImagEngine - ONE LINE - Added $file as array, for Text Images
if (!is_array($file) && file_exists($file)) {
$this->file = $file;
$info = getimagesize($file);
$this->info = array('width' => $info[0], 'height' => $info[1], 'bits' => isset($info['bits']) ? $info['bits'] : '', 'mime' => isset($info['mime']) ? $info['mime'] : '');
// BOF - Zappo - ImagEngine - Calculate needed Memory, and set memory to that value, so we can do needed calculations
$memoryNeeded = round(($info[0] * $info[1] * $info['bits'] * 4 / 8 + Pow(2, 16)) * 1.65);
if (function_exists('memory_get_usage') && memory_get_usage() + $memoryNeeded > (int) ini_get('memory_limit') * pow(1024, 2)) {
ini_set('memory_limit', (int) ini_get('memory_limit') + ceil((memory_get_usage() + $memoryNeeded - (int) ini_get('memory_limit') * pow(1024, 2)) / pow(1024, 2)) . 'M');
}
// EOF - Zappo - ImagEngine - Calculate needed Memory, and set memory to that value, so we can do needed calculations
$this->image = $this->create($file);
} else {
// BOF - Zappo - ImagEngine - If image doesn't exist, create one (for text images 'n stuff)
$w = is_array($file) ? $file[0] : 5;
$h = is_array($file) ? $file[1] : 5;
$this->image = imagecreatetruecolor($w, $h);
if (is_array($file) && isset($file[2]) && $file[2]) {
$r = hexdec(substr($file[2], 0, 2));
$g = hexdec(substr($file[2], 2, 2));
$b = hexdec(substr($file[2], 4, 2));
$trans_color = imagecolorallocate($this->image, $r, $g, $b);
} else {
imagesavealpha($this->image, true);
$trans_color = imagecolorallocatealpha($this->image, 0, 0, 0, 127);
}
imagefill($this->image, 0, 0, $trans_color);
$this->info = array('width' => $w, 'height' => $h, 'mime' => 'image/png');
// EOF - Zappo - ImagEngine - If image doesn't exist, create one (for text images 'n stuff)
}
}
示例2: hasMemoryForImage
function hasMemoryForImage($serverFilename)
{
// find out how much total memory this script can access
$memoryAvailable = return_bytes(@ini_get('memory_limit'));
// if memory is unlimited, it will return -1 and we don’t need to worry about it
if ($memoryAvailable == -1) {
return true;
}
// find out how much memory we are already using
$memoryUsed = memory_get_usage();
$imgsize = @getimagesize($serverFilename);
// find out how much memory this image needs for processing, probably only works for jpegs
// from comments on http://www.php.net/imagecreatefromjpeg
if (is_array($imgsize) && isset($imgsize['bits']) && isset($imgsize['channels'])) {
$memoryNeeded = round(($imgsize[0] * $imgsize[1] * $imgsize['bits'] * $imgsize['channels'] / 8 + Pow(2, 16)) * 1.65);
$memorySpare = $memoryAvailable - $memoryUsed - $memoryNeeded;
if ($memorySpare > 0) {
// we have enough memory to load this file
return true;
} else {
// not enough memory to load this file
$image_info = sprintf('%.2fKB, %d × %d %d bits %d channels', filesize($serverFilename) / 1024, $imgsize[0], $imgsize[1], $imgsize['bits'], $imgsize['channels']);
Log::addMediaLog('Cannot create thumbnail ' . $serverFilename . ' (' . $image_info . ') memory avail: ' . $memoryAvailable . ' used: ' . $memoryUsed . ' needed: ' . $memoryNeeded . ' spare: ' . $memorySpare);
return false;
}
} else {
// assume there is enough memory
// TODO find out how to check memory needs for gif and png
return true;
}
}
示例3: _setMemoryLimitForImage
function _setMemoryLimitForImage($image_path)
{
$imageInfo = getimagesize($image_path);
$imageInfo['channels'] = !empty($imageInfo['channels']) ? $imageInfo['channels'] : 1;
$imageInfo['bits'] = !empty($imageInfo['bits']) ? $imageInfo['bits'] : 1;
$memoryNeeded = round(($imageInfo[0] * $imageInfo[1] * $imageInfo['bits'] * $imageInfo['channels'] / 8 + Pow(2, 16)) * 1.65);
if (function_exists('memory_get_usage') && memory_get_usage() + $memoryNeeded > (int) ini_get('memory_limit') * pow(1024, 2)) {
ini_set('memory_limit', (int) ini_get('memory_limit') + ceil((memory_get_usage() + $memoryNeeded - (int) ini_get('memory_limit') * pow(1024, 2)) / pow(1024, 2)) . 'M');
}
}
示例4: setMemoryForBigImage
/**
* Set memory in case of very big images (more than 1Mb)
* new SmartImage($src, true) to activate this function
* Works with (PHP 4 >= 4.3.2, PHP 5) if compiled with --enable-memory-limit
* or PHP>=5.2.1
* Thanks to Andrvm and to Bascunan for this feature
*/
private function setMemoryForBigImage($filename)
{
$imageInfo = getimagesize($filename);
$memoryNeeded = round(($imageInfo[0] * $imageInfo[1] * $imageInfo['bits'] * $imageInfo['channels'] / 8 + Pow(2, 16)) * 1.65);
$memoryLimit = (int) ini_get('memory_limit') * 1048576;
if (memory_get_usage() + $memoryNeeded > $memoryLimit) {
ini_set('memory_limit', ceil((memory_get_usage() + $memoryNeeded + $memoryLimit) / 1048576) . 'M');
return true;
} else {
return false;
}
}
示例5: _getImageNeedMemorySize
/**
* Get image needed memory size
*
* @param string $file
* @return float|int
*/
protected function _getImageNeedMemorySize($file)
{
$imageInfo = getimagesize($file);
if (!isset($imageInfo[0]) || !isset($imageInfo[1])) {
return 0;
}
if (!isset($imageInfo['channels'])) {
// if there is no info about this parameter lets set it for maximum
$imageInfo['channels'] = 4;
}
if (!isset($imageInfo['bits'])) {
// if there is no info about this parameter lets set it for maximum
$imageInfo['bits'] = 8;
}
return round(($imageInfo[0] * $imageInfo[1] * $imageInfo['bits'] * $imageInfo['channels'] / 8 + Pow(2, 16)) * 1.65);
}
示例6: getMemoryNeeded
/**
* Takes memory required to process supplied image file and a bit more for future PHP operations.
* @param resource $imageFile
* @return bool true on success
*/
protected function getMemoryNeeded($imageFile)
{
if (!file_exists($imageFile)) {
return 0;
}
$imageInfo = getimagesize($imageFile);
if (!isset($imageInfo['channels']) || !$imageInfo['channels']) {
$imageInfo['channels'] = 4;
}
if (!isset($imageInfo['bits']) || !$imageInfo['bits']) {
$imageInfo['bits'] = 8;
}
if (!isset($imageInfo[0])) {
$imageInfo[0] = 1;
}
if (!isset($imageInfo[1])) {
$imageInfo[1] = 1;
}
$memoryNeeded = round(($imageInfo[0] * $imageInfo[1] * $imageInfo['bits'] * $imageInfo['channels'] / 8 + Pow(2, 16)) * 1.65);
$success = \Ip\Internal\System\Helper\SystemInfo::allocateMemory($memoryNeeded);
return $success;
}
示例7: get_gd_resource
/**
* @param string $filename
* @return resource|string
*/
private function get_gd_resource($filename)
{
$mime = $this->info['mime'];
//some images processing can run out of original PHP memory limit size
//Dynamic memory allocation based on K.Tamutis solution on the php manual
$mem_estimate = round(($this->info['width'] * $this->info['height'] * $this->info['bits'] * $this->info['channels'] / 8 + Pow(2, 16)) * 1.7);
if (function_exists('memory_get_usage')) {
if (memory_get_usage() + $mem_estimate > (int) ini_get('memory_limit') * pow(1024, 2)) {
$new_mem = (int) ini_get('memory_limit') + ceil((memory_get_usage() + $mem_estimate - (int) ini_get('memory_limit') * pow(1024, 2)) / pow(1024, 2)) . 'M';
//TODO. Validate if memory change was in fact changed or report an error
ini_set('memory_limit', $new_mem);
}
}
$res_img = '';
if ($mime == 'image/gif') {
$res_img = imagecreatefromgif($filename);
} elseif ($mime == 'image/png') {
$res_img = imagecreatefrompng($filename);
} elseif ($mime == 'image/jpeg') {
$res_img = imagecreatefromjpeg($filename);
}
return $res_img;
}
示例8: setMemoryForImage
public static function setMemoryForImage($filename)
{
$imageInfo = getimagesize($filename);
$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 = (int) ini_get('memory_limit');
$memoryLimit = $memoryLimitMB * $MB;
if (function_exists('memory_get_usage') && $memoryHave + $memoryNeeded > $memoryLimit) {
$newLimit = $memoryLimitMB + ceil(($memoryHave + $memoryNeeded - $memoryLimit) / $MB);
ini_set('memory_limit', $newLimit . 'M');
if ($newLimit > (int) ini_get('memory_limit')) {
return false;
} else {
return true;
}
} else {
return true;
}
}
示例9: _jpegMemoryAllocation
/**
* Calculate and set memory for jpeg
* Credit to Karolis Tamutis karolis.t_AT_gmail.com
*
* @param string $path
*/
private function _jpegMemoryAllocation($path)
{
$memoryNeeded = round(($this->_gdImageData[0] * $this->_gdImageData[1] * $this->_gdImageData['bits'] * $this->_gdImageData['channels'] / 8 + Pow(2, 16)) * 1.65);
if (function_exists('memory_get_usage') && memory_get_usage() + $memoryNeeded > (int) ini_get('memory_limit') * pow(1024, 2)) {
ini_set('memory_limit', (int) ini_get('memory_limit') + ceil((memory_get_usage() + $memoryNeeded - (int) ini_get('memory_limit') * pow(1024, 2)) / pow(1024, 2)) . 'M');
}
}
示例10: setMemory
private function setMemory($imageVar)
{
$imageInfo = getimagesize($this->{$imageVar});
$memoryNeeded = round(($imageInfo[0] * $imageInfo[1] * $imageInfo['bits'] * $imageInfo['channels'] / 8 + Pow(2, 16)) * 1.65);
if (function_exists('memory_get_usage') && memory_get_usage() + $memoryNeeded > (int) ini_get('memory_limit') * pow(1024, 2)) {
ini_set('memory_limit', 2 * (int) ini_get('memory_limit') + ceil((memory_get_usage() + $memoryNeeded - (int) ini_get('memory_limit') * pow(1024, 2)) / pow(1024, 2)) . 'M');
}
}
示例11: _getNeedMemoryForFile
protected function _getNeedMemoryForFile($file = null)
{
$file = is_null($file) ? $this->getBaseFile() : $file;
if (!$file) {
return 0;
}
if (!file_exists($file) || !is_file($file)) {
return 0;
}
try {
$imageInfo = getimagesize($file);
} catch (Exception $e) {
return 0;
}
if (!isset($imageInfo[0]) || !isset($imageInfo[1])) {
return 0;
}
if (!isset($imageInfo['channels'])) {
// if there is no info about this parameter lets set it for maximum
$imageInfo['channels'] = 4;
}
if (!isset($imageInfo['bits'])) {
// if there is no info about this parameter lets set it for maximum
$imageInfo['bits'] = 8;
}
return round(($imageInfo[0] * $imageInfo[1] * $imageInfo['bits'] * $imageInfo['channels'] / 8 + Pow(2, 16)) * 1.65);
}
示例12: createThumbnail
/**
* createThumbnail
*
* G�n�re la vignette d'une image en fonction d'une taille donn�e
*
* @author Fr�d�ric Mossmann <fmossmann@cap-tic.fr>
* @param string $album Nom de la photo et cl�, s�par�s par '_'
* @param string $file Nom de l'album et cl�, s�par�s par '_'
* @param string $ext Extension de la photo (jpg, gif, etc.)
* @param string $taille Taille de la vignette � cr�er (avec 's' pour un format carr�)
* @param boolean $force Force la cr�ation de la vignette, m�me si elle existe d�j�
*/
public function createThumbnail($album, $file, $ext, $taille = "s128", $force = false, $toext = '')
{
$memoryLimit = ini_get("memory_limit");
switch (substr($memoryLimit, -1)) {
case 'K':
$memoryLimit = 1024 * (int) substr($memoryLimit, 0, -1);
break;
case 'M':
$memoryLimit = 1024 * 1024 * (int) substr($memoryLimit, 0, -1);
break;
case 'G':
$memoryLimit = 1024 * 1024 * 1024 * (int) substr($memoryLimit, 0, -1);
break;
}
// A faire dans le .htaccess
// @ini_set( 'memory_limit', '64M' );
@ini_set('max_execution_time', '120');
$path2data = realpath("static");
$pathfolder = $path2data . '/album/' . $album;
$pathfile = $pathfolder . '/' . $file . '.' . $ext;
if ($toext != '') {
// Changement de format
$savedfile = $pathfolder . '/' . $file . '_' . $taille . '.' . $toext;
if (file_exists($savedfile) && !$force) {
return true;
}
} else {
// Conservation du format
$savedfile = $pathfolder . '/' . $file . '_' . $taille . '.' . $ext;
if (file_exists($savedfile) && !$force) {
return true;
}
}
// D�codage de la taille ('s' pour carr�e et nombre de pixels)
if (ereg("^s([0-9]+)\$", $taille, $regs)) {
$size = $regs[1];
$mode = "square";
} else {
$size = $taille;
$mode = "normal";
}
// R�cup�ration des infos de l'image (sinon erreur)
$file_info = getimagesize($pathfile);
if ($file_info == false) {
//echo "Erreur : ".$pathfile;
return false;
}
list($width, $height, $type, $attr) = $file_info;
// SQUARE //
if ($mode == "square") {
$square_width = $width;
$square_height = $height;
if ($square_width >= $square_height) {
// Plus large que haut
$square_y = 0;
$square_size = $square_height;
$square_x = round($square_width - $square_height) / 2;
} else {
// Plus haut que large
$square_x = 0;
$square_size = $square_width;
$square_y = round($square_height - $square_width) / 2;
}
$square_thumbsize = $size;
}
$ratio = max($width, $height) / $size;
// Doit-on r�duite l'image ?
if ($ratio > 1) {
$new_width = round($width / $ratio);
$new_height = round($height / $ratio);
} else {
$new_width = $width;
$new_height = $height;
}
// M�moire d�j� utilis�e par PHP et Iconito
$memoryUsed = memory_get_usage();
// M�moire pr�vue pour ouvrir le fichier original
if (!isset($file_info['channels'])) {
$file_info['channels'] = 4;
}
// Normalement 3, mais au pire avec l'AlphaChannel, on prend 4.
if (!isset($file_info['bits'])) {
$file_info['bits'] = 8;
}
// 8 bits.
$memoryNeeded = round(($file_info[0] * $file_info[1] * $file_info['bits'] * $file_info['channels'] / 8 + Pow(2, 16)) * 1.65);
// M�moire pr�vue pour ouvrir la vignette (en pr�voyant un peu large)
$memoryNeeded += round((1024 * 1024 * 8 * 4 / 8 + Pow(2, 16)) * 1.65);
//.........这里部分代码省略.........
示例13: updateItemTable
function updateItemTable()
{
global $thumbnailSizes;
executeQueryForUpdate("\n ALTER TABLE @item \n DROP title, DROP picture, DROP keepPrivate,\n CHANGE `active` `status` INT NOT NULL DEFAULT 1, \n CHANGE `expirationTime` `expirationTime` DATETIME NOT NULL, \n CHANGE `creationtime` `creationtime` DATETIME NOT NULL;", __FILE__, __LINE__);
executeQueryForUpdate("UPDATE @item SET `expirationTime`=0, expEmailSent=0", __FILE__, __LINE__);
G::load($cats, "SELECT * FROM @category WHERE expiration!=0");
foreach ($cats as $cat) {
executeQueryForUpdate("UPDATE @item SET `expirationTime`= NOW() + INTERVAL {$cat->expiration} DAY WHERE cid={$cat->id};", __FILE__, __LINE__);
}
CustomField::addCustomColumns("item");
G::load($items, "SELECT * FROM @item WHERE col_1!=''");
$create_fg = array("", "ImageCreateFromGIF", "ImageCreateFromJPEG", "ImageCreateFromPNG");
$save_fg = array("", "ImageGIF", "ImageJPEG", "ImagePNG");
$extensions = array("", "gif", "jpg", "png");
$checkBits = array(0, IMG_GIF, IMG_JPG, IMG_PNG);
$memoryLimit = byteStr2num(ini_get('memory_limit'));
foreach ($items as $item) {
$ext = strstr($item->col_1, "jpg") ? "jpg" : (strstr($item->col_1, "gif") ? "gif" : (strstr($item->col_1, "png") ? "png" : ""));
if (!$ext) {
continue;
}
executeQueryForUpdate("UPDATE @item SET col_1='{$ext}' WHERE id={$item->id}", __FILE__, __LINE__);
$fname = AD_PIC_DIR . "/{$item->id}.{$ext}";
if (file_exists($fname)) {
@unlink(AD_PIC_DIR . "/th_{$item->id}.{$ext}");
// a regi thumbnailt toroljuk
copy($fname, AD_PIC_DIR . "/{$item->id}_1.{$ext}");
// uj nev a full image-nek
// mas fg-eket kell hivni az image tipusnak megfeleloen:
$size = getimagesize($fname);
$width = $size[0];
$height = $size[1];
$type = $size[2];
// az image tipus, 1=>GIF, 2=>JPG, 3=>PNG
$ext = $extensions[$type];
$supported = FALSE;
if (defined("IMG_GIF") && function_exists("ImageTypes")) {
$supported = isset($checkBits[$type]) && ImageTypes() & $checkBits[$type];
}
// ha az adott image tipus supportalva van:
if ($supported) {
foreach ($thumbnailSizes as $thSize => $dimensions) {
if (function_exists('memory_get_usage') && $memoryLimit && $memoryLimit != -1) {
$channels = isset($size['channels']) ? $size['channels'] : 1;
// png has no channels
$memoryNeeded = Round(($size[0] * $size[1] * $size['bits'] * $channels / 8 + Pow(2, 16)) * 1.65);
$usage = memory_get_usage();
//FP::log("Current usage: $usage, limit: $memoryLimit, new to allocate: $memoryNeeded, rest after allocate: ". ($memoryLimit-$usage-$memoryNeeded));
// skipping if ImageCreate would exceed the memory limit:
if ($usage + $memoryNeeded > $memoryLimit) {
continue;
}
}
shrinkPicture($newWidth, $newHeight, $dimensions["width"], $dimensions["height"], $fname);
$src_im = $create_fg[$type]($fname);
$dst_im = ImageCreateTrueColor($newWidth, $newHeight);
imagecopyresampled($dst_im, $src_im, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
$th_foname = AD_PIC_DIR . "/th_{$thSize}_{$item->id}_1.{$ext}";
// pictures/ads/th_medium_2345_5.jpg
$save_fg[$type]($dst_im, $th_foname);
imagedestroy($src_im);
}
}
@unlink($fname);
// a full image-et a regi neven toroljuk
}
}
global $gorumuser, $gorumrecognised;
$gorumrecognised = TRUE;
$gorumuser->isAdm = 1;
$c = new AppCategory();
$c->recalculateAllItemNums(TRUE);
}
示例14: haveEnoughMemory
/**
* haveEnoughMemory
*
* Calculates whether the given image can be resized with the current available memory.
*
* @return boolean
*/
private function haveEnoughMemory()
{
$this->memoryAvailable = ini_get('memory_limit');
$this->memoryAvailable = substr($this->memoryAvailable, 0, -1);
$this->memoryAvailable = $this->memoryAvailable * 1024 * 1024;
$size = $this->destination->getImageSize($this->destination->destinationPath . $this->fileName);
// channels and bits are not present on all images
if (!isset($size['channels'])) {
$size['channels'] = 3;
}
if (!isset($size['bits'])) {
$size['bits'] = 8;
}
$this->memoryNeeded = Round(($size[0] * $size[1] * $size['bits'] * $size['channels'] / 8 + Pow(2, 16)) * 1.65);
if ($this->memoryNeeded > $this->memoryAvailable) {
// Try to delete from server
$this->destination->deleteFile($this->fileName);
$this->fcmsError->add(array('message' => T_('Out of Memory Warning'), 'details' => '<p>' . T_('The photo you are trying to upload is quite large and the server might run out of memory if you continue.') . '<small>(' . number_format($this->memoryNeeded) . ' / ' . number_format($this->memoryAvailable) . ')</small></p>'));
return false;
}
return true;
}
示例15: load_image
/**
* Load an image from a file into memory
*
* @param string pathname of image file
* @param string
* @return array resource image handle or NULL
*/
function load_image($path, $mimetype)
{
// yabs> GD library uses shedloads of memory
// fp> 256M is way too high to sneak this in here. There should be some checks in the systems page to warn against low memory conditions. Also i'm not sure it makes sense to bump memory just for images. If you allow memory you might as well allow it for anything. Anyways, this is too much to be snuk in.
// @ini_set('memory_limit', '256M'); // artificially inflate memory if we can
$err = NULL;
$imh = NULL;
$function = NULL;
$image_info = getimagesize($path);
if (!$image_info || $image_info['mime'] != $mimetype) {
$FiletypeCache = get_Cache('FiletypeCache');
$correct_Filetype = $FiletypeCache->get_by_mimetype($image_info['mime']);
$correct_extension = array_shift($correct_Filetype->get_extensions());
$path_info = pathinfo($path);
$wrong_extension = $path_info['extension'];
$err = '!' . $correct_extension . ' extension mismatch: use .' . $correct_extension . ' instead of .' . $wrong_extension;
} else {
$mime_function = array('image/jpeg' => 'imagecreatefromjpeg', 'image/gif' => 'imagecreatefromgif', 'image/png' => 'imagecreatefrompng');
if (isset($mime_function[$mimetype])) {
$function = $mime_function[$mimetype];
} else {
// Unrecognized mime type
$err = '!Unsupported format ' . $mimetype . ' (load_image)';
}
}
//pre_dump( $function );
if ($function) {
// Call GD built-in function to load image
// fp> Note: sometimes this GD call will die and there is no real way to recover :/
load_funcs('tools/model/_system.funcs.php');
$memory_limit = system_check_memory_limit();
$curr_mem_usage = memory_get_usage(true);
// Calculate the aproximative memory size which would be required to create the image resource
$tweakfactor = 1.8;
// Or whatever works for you
$memory_needed = round(($image_info[0] * $image_info[1] * (isset($image_info['bits']) ? $image_info['bits'] : 4) * (isset($image_info['channels']) ? $image_info['channels'] / 8 : 1) + Pow(2, 16)) * $tweakfactor);
if ($memory_limit - $curr_mem_usage < $memory_needed) {
// Don't try to load the image into the memory because it would cause 'Allowed memory size exhausted' error
return array("!Cannot resize too large image", false);
}
$imh = $function($path);
}
if ($imh === false) {
trigger_error('load_image failed: ' . $path . ' / ' . $mimetype);
// DEBUG
// e.g. "imagecreatefromjpeg(): $FILE is not a valid JPEG file"
$err = '!load_image failed (no valid image?)';
}
if ($err) {
error_log('load_image failed: ' . substr($err, 1) . ' (' . $path . ' / ' . $mimetype . ')');
}
return array($err, $imh);
}