Skip to content

Commit

Permalink
Merge branch 'rlerdorf-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
dapphp committed Sep 9, 2015
2 parents 45302f1 + a4b44b4 commit c783306
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 34 deletions.
33 changes: 23 additions & 10 deletions WavFile.php
Expand Up @@ -169,7 +169,7 @@ class WavFile
/** @var int Size of the data chunk in the opened wav file */
protected $_dataSize_fp;

/** @var int Does _dataSize really reflect strlen($_samples)? Case when a wav file is read with readData = false */
/** @var bool Does _dataSize really reflect strlen($_samples)? Case when a wav file is read with readData = false */
protected $_dataSize_valid;

/** @var int Starting offset of data chunk */
Expand All @@ -178,7 +178,7 @@ class WavFile
/** @var int The audio format - WavFile::WAVE_FORMAT_* */
protected $_audioFormat;

/** @var int The audio subformat - WavFile::WAVE_SUBFORMAT_* */
/** @var int|string|null The audio subformat - WavFile::WAVE_SUBFORMAT_* */
protected $_audioSubFormat;

/** @var int Number of channels in the audio file */
Expand Down Expand Up @@ -211,7 +211,7 @@ class WavFile
/** @var string Binary string of samples */
protected $_samples;

/** @var resource The file pointer used for reading wavs from file or memory */
/** @var resource|null The file pointer used for reading wavs from file or memory */
protected $_fp;


Expand Down Expand Up @@ -296,7 +296,7 @@ public function __toString()
*
* @param string $sampleBinary (Required) The sample to decode.
* @param int $bitDepth (Optional) The bits per sample to decode. If omitted, derives it from the length of $sampleBinary.
* @return int|float The numeric sample value. Float for 32-bit samples. Returns null for unsupported bit depths.
* @return int|float|null The numeric sample value. Float for 32-bit samples. Returns null for unsupported bit depths.
*/
public static function unpackSample($sampleBinary, $bitDepth = null)
{
Expand Down Expand Up @@ -342,7 +342,7 @@ public static function unpackSample($sampleBinary, $bitDepth = null)
*
* @param int|float $sample (Required) The sample to encode. Has to be within valid range for $bitDepth. Float values only for 32 bits.
* @param int $bitDepth (Required) The bits per sample to encode with.
* @return string The encoded binary sample. Returns null for unsupported bit depths.
* @return string|null The encoded binary sample. Returns null for unsupported bit depths.
*/
public static function packSample($sample, $bitDepth)
{
Expand Down Expand Up @@ -469,6 +469,7 @@ public function getActualSize() {
return $this->_actualSize;
}

/** @param int $actualSize */
protected function setActualSize($actualSize = null) {
if (is_null($actualSize)) {
$this->_actualSize = 8 + $this->_chunkSize; // + "RIFF" header (ID + size)
Expand All @@ -483,6 +484,7 @@ public function getChunkSize() {
return $this->_chunkSize;
}

/** @param int $chunkSize */
protected function setChunkSize($chunkSize = null) {
if (is_null($chunkSize)) {
$this->_chunkSize = 4 + // "WAVE" chunk
Expand All @@ -503,6 +505,7 @@ public function getFmtChunkSize() {
return $this->_fmtChunkSize;
}

/** @param int $fmtChunkSize */
protected function setFmtChunkSize($fmtChunkSize = null) {
if (is_null($fmtChunkSize)) {
$this->_fmtChunkSize = 16 + $this->_fmtExtendedSize;
Expand All @@ -520,6 +523,7 @@ public function getFmtExtendedSize() {
return $this->_fmtExtendedSize;
}

/** @param int $fmtExtendedSize */
protected function setFmtExtendedSize($fmtExtendedSize = null) {
if (is_null($fmtExtendedSize)) {
if ($this->_audioFormat == self::WAVE_FORMAT_EXTENSIBLE) {
Expand All @@ -542,6 +546,7 @@ public function getFactChunkSize() {
return $this->_factChunkSize;
}

/** @param int $factChunkSize */
protected function setFactChunkSize($factChunkSize = null) {
if (is_null($factChunkSize)) {
if ($this->_audioFormat != self::WAVE_FORMAT_PCM) {
Expand All @@ -563,6 +568,7 @@ public function getDataSize() {
return $this->_dataSize;
}

/** @param int $dataSize */
protected function setDataSize($dataSize = null) {
if (is_null($dataSize)) {
$this->_dataSize = strlen($this->_samples);
Expand All @@ -581,6 +587,7 @@ public function getDataOffset() {
return $this->_dataOffset;
}

/** @param int $dataOffset */
protected function setDataOffset($dataOffset = null) {
if (is_null($dataOffset)) {
$this->_dataOffset = 8 + // "RIFF" header (ID + size)
Expand All @@ -599,6 +606,7 @@ public function getAudioFormat() {
return $this->_audioFormat;
}

/** @param int $audioFormat */
protected function setAudioFormat($audioFormat = null) {
if (is_null($audioFormat)) {
if (($this->_bitsPerSample <= 16 || $this->_bitsPerSample == 32)
Expand Down Expand Up @@ -628,6 +636,7 @@ public function getAudioSubFormat() {
return $this->_audioSubFormat;
}

/** @param int $audioSubFormat */
protected function setAudioSubFormat($audioSubFormat = null) {
if (is_null($audioSubFormat)) {
if ($this->_bitsPerSample == 32) {
Expand All @@ -646,6 +655,7 @@ public function getNumChannels() {
return $this->_numChannels;
}

/** @param int $numChannels */
public function setNumChannels($numChannels) {
if ($numChannels < 1 || $numChannels > self::MAX_CHANNEL) {
throw new WavFileException('Unsupported number of channels. Only up to ' . self::MAX_CHANNEL . ' channels are supported.');
Expand Down Expand Up @@ -748,6 +758,7 @@ public function getBlockAlign() {
return $this->_blockAlign;
}

/** @param int $blockAlign */
protected function setBlockAlign($blockAlign = null) {
if (is_null($blockAlign)) {
$this->_blockAlign = $this->_numChannels * $this->_bitsPerSample / 8;
Expand All @@ -765,6 +776,7 @@ public function getNumBlocks()
return $this->_numBlocks;
}

/** @param int $numBlocks */
protected function setNumBlocks($numBlocks = null) {
if (is_null($numBlocks)) {
$this->_numBlocks = (int)($this->_dataSize / $this->_blockAlign); // do not count incomplete sample blocks
Expand All @@ -779,6 +791,7 @@ public function getByteRate() {
return $this->_byteRate;
}

/** @param int $byteRate */
protected function setByteRate($byteRate = null) {
if (is_null($byteRate)) {
$this->_byteRate = $this->_sampleRate * $this->_numChannels * $this->_bitsPerSample / 8;
Expand Down Expand Up @@ -1016,7 +1029,7 @@ public function setWavData(&$data, $free = true)
/**
* Read wav file from a stream.
*
* @param $readData (Optional) If true, also read the data chunk.
* @param bool $readData (Optional) If true, also read the data chunk.
* @throws WavFormatException
* @throws WavFileException
*/
Expand Down Expand Up @@ -1292,8 +1305,8 @@ protected function readWavHeader()
/**
* Read the wav data from the file into the buffer.
*
* @param $dataOffset (Optional) The byte offset to skip before starting to read. Must be a multiple of BlockAlign.
* @param $dataSize (Optional) The size of the data to read in bytes. Must be a multiple of BlockAlign. Defaults to all data.
* @param int $dataOffset (Optional) The byte offset to skip before starting to read. Must be a multiple of BlockAlign.
* @param int $dataSize (Optional) The size of the data to read in bytes. Must be a multiple of BlockAlign. Defaults to all data.
* @throws WavFileException
*/
public function readWavData($dataOffset = 0, $dataSize = null)
Expand Down Expand Up @@ -1335,7 +1348,7 @@ public function readWavData($dataOffset = 0, $dataSize = null)
* Return a single sample block from the file.
*
* @param int $blockNum (Required) The sample block number. Zero based.
* @return string The binary sample block (all channels). Returns null if the sample block number was out of range.
* @return string|null The binary sample block (all channels). Returns null if the sample block number was out of range.
*/
public function getSampleBlock($blockNum)
{
Expand Down Expand Up @@ -1404,7 +1417,7 @@ public function setSampleBlock($sampleBlock, $blockNum)
*
* @param int $blockNum (Required) The sample block number to fetch. Zero based.
* @param int $channelNum (Required) The channel number within the sample block to fetch. First channel is 1.
* @return float The float sample value. Returns null if the sample block number was out of range.
* @return float|null The float sample value. Returns null if the sample block number was out of range.
* @throws WavFileException
*/
public function getSampleValue($blockNum, $channelNum)
Expand Down
50 changes: 26 additions & 24 deletions securimage.php
Expand Up @@ -300,25 +300,25 @@ class Securimage

/**
* The background color of the captcha
* @var Securimage_Color
* @var Securimage_Color|string
*/
public $image_bg_color = '#ffffff';

/**
* The color of the captcha text
* @var Securimage_Color
* @var Securimage_Color|string
*/
public $text_color = '#707070';

/**
* The color of the lines over the captcha
* @var Securimage_Color
* @var Securimage_Color|string
*/
public $line_color = '#707070';

/**
* The color of the noise that is drawn
* @var Securimage_Color
* @var Securimage_Color|string
*/
public $noise_color = '#707070';

Expand Down Expand Up @@ -415,7 +415,7 @@ class Securimage

/**
* The color of the signature text
* @var Securimage_Color
* @var Securimage_Color|string
*/
public $signature_color = '#707070';

Expand Down Expand Up @@ -743,7 +743,7 @@ class Securimage

/**
* The background image GD resource
* @var resource
* @var string
*/
protected $bgimg;

Expand All @@ -769,7 +769,7 @@ class Securimage
* Either the case-sensitive/insensitive word captcha, or the solution to
* the math captcha.
*
* @var string Captcha challenge value
* @var string|bool Captcha challenge value
*/
protected $code;

Expand Down Expand Up @@ -844,35 +844,35 @@ class Securimage
/**
* PDO connection when a database is used
*
* @var resource
* @var PDO|bool
*/
protected $pdo_conn;

/**
* The GD color resource for the background color
* The GD color for the background color
*
* @var resource
* @var int
*/
protected $gdbgcolor;

/**
* The GD color resource for the text color
* The GD color for the text color
*
* @var resource
* @var int
*/
protected $gdtextcolor;

/**
* The GD color resource for the line color
* The GD color for the line color
*
* @var resource
* @var int
*/
protected $gdlinecolor;

/**
* The GD color resource for the signature text color
* The GD color for the signature text color
*
* @var resource
* @var int
*/
protected $gdsignaturecolor;

Expand Down Expand Up @@ -1310,6 +1310,7 @@ public function setNamespace($namespace)
* $img->outputAudioFile(); // outputs a wav file to the browser
* exit;
*
* @param string $format
*/
public function outputAudioFile($format = null)
{
Expand Down Expand Up @@ -1596,6 +1597,7 @@ protected function setBackground()

/**
* Scan the directory for a background image to use
* @return string|bool
*/
protected function getBackgroundFromDirectory()
{
Expand Down Expand Up @@ -1641,7 +1643,7 @@ public function createCode()
}
} while ($c <= 0); // no negative #'s or 0

$this->code = $c;
$this->code = "$c";
$this->code_display = "$left $sign $right";
break;
}
Expand Down Expand Up @@ -1694,7 +1696,7 @@ protected function drawWord()
$x = floor($width2 / 2 - $tx / 2 - $bb[0]);
$y = round($height2 / 2 - $ty / 2 - $bb[1]);

imagettftext($this->tmpimg, $font_size, 0, $x, $y, $this->gdtextcolor, $this->ttf_file, $this->code_display);
imagettftext($this->tmpimg, $font_size, 0, (int)$x, (int)$y, $this->gdtextcolor, $this->ttf_file, $this->code_display);
} else {
$font_size = $this->image_height * $ratio;
$bb = imageftbbox($font_size, 0, $this->ttf_file, $this->code_display);
Expand All @@ -1703,7 +1705,7 @@ protected function drawWord()
$x = floor($this->image_width / 2 - $tx / 2 - $bb[0]);
$y = round($this->image_height / 2 - $ty / 2 - $bb[1]);

imagettftext($this->im, $font_size, 0, $x, $y, $this->gdtextcolor, $this->ttf_file, $this->code_display);
imagettftext($this->im, $font_size, 0, (int)$x, (int)$y, $this->gdtextcolor, $this->ttf_file, $this->code_display);
}
}

Expand Down Expand Up @@ -1955,7 +1957,7 @@ protected function getAudibleCode()
* Seek to a random offset in the file and reads a block of data and returns a line from the file.
*
* @param int $numWords Number of words (lines) to read from the file
* @return string|array Returns a string if only one word is to be read, or an array of words
* @return string|array|bool Returns a string if only one word is to be read, or an array of words
*/
protected function readCodeFromFile($numWords = 1)
{
Expand Down Expand Up @@ -2207,7 +2209,7 @@ protected function openDatabase()
}
} catch (Exception $ex) {
trigger_error($ex->getMessage(), E_USER_WARNING);
$this->pdo_conn = null;
$this->pdo_conn = false;
return false;
}

Expand Down Expand Up @@ -2453,8 +2455,8 @@ protected function purgeOldCodesFromDatabase()

$query = sprintf("DELETE FROM %s WHERE %s - created > %s",
$this->database_table,
$this->pdo_conn->quote($now, PDO::PARAM_INT),
$this->pdo_conn->quote($limit, PDO::PARAM_INT));
$now,
$this->pdo_conn->quote("$limit", PDO::PARAM_INT));

$result = $this->pdo_conn->query($query);
}
Expand Down Expand Up @@ -2886,7 +2888,7 @@ function frand()
/**
* Convert an html color code to a Securimage_Color
* @param string $color
* @param Securimage_Color $default The defalt color to use if $color is invalid
* @param Securimage_Color|string $default The defalt color to use if $color is invalid
*/
protected function initColor($color, $default)
{
Expand Down

0 comments on commit c783306

Please sign in to comment.