Skip to content

Improve debug logging #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 30, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 88 additions & 12 deletions src/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ private static function unwrap(array $result): array
private static function isImage($value): bool
{
return is_resource($value) &&
get_resource_type($value) === 'GObject';
get_resource_type($value) === 'GObject';
}

/**
Expand Down Expand Up @@ -774,10 +774,19 @@ public static function newFromFile(
string $filename,
array $options = []
): Image {
Utils::debugLog('newFromFile', [
'instance' => null,
'arguments' => [$filename, $options]
]);

$options = self::unwrap($options);
$result = vips_image_new_from_file($filename, $options);
self::errorIsArray($result);
return self::wrapResult($result);
$result = self::wrapResult($result);

Utils::debugLog('newFromFile', ['result' => $result]);

return $result;
}

/**
Expand All @@ -791,6 +800,11 @@ public static function newFromFile(
*/
public static function findLoad(string $filename)
{
Utils::debugLog('findLoad', [
'instance' => null,
'arguments' => [$filename]
]);

// added in 1.0.5 of the binary module
if (function_exists('vips_foreign_find_load')) {
$result = vips_foreign_find_load($filename);
Expand All @@ -808,6 +822,8 @@ public static function findLoad(string $filename)
}
}

Utils::debugLog('findLoad', ['result' => [$result]]);

return $result;
}

Expand All @@ -826,10 +842,19 @@ public static function newFromBuffer(
string $option_string = '',
array $options = []
): Image {
Utils::debugLog('newFromBuffer', [
'instance' => null,
'arguments' => [$buffer, $option_string, $options]
]);

$options = self::unwrap($options);
$result = vips_image_new_from_buffer($buffer, $option_string, $options);
self::errorIsArray($result);
return self::wrapResult($result);
$result = self::wrapResult($result);

Utils::debugLog('newFromBuffer', ['result' => $result]);

return $result;
}

/**
Expand All @@ -843,6 +868,11 @@ public static function newFromBuffer(
*/
public static function findLoadBuffer(string $buffer)
{
Utils::debugLog('findLoadBuffer', [
'instance' => null,
'arguments' => [$buffer]
]);

// added in 1.0.5 of the binary module
if (function_exists('vips_foreign_find_load_buffer')) {
$result = vips_foreign_find_load_buffer($buffer);
Expand All @@ -861,6 +891,8 @@ public static function findLoadBuffer(string $buffer)
}
}

Utils::debugLog('findLoadBuffer', ['result' => [$result]]);

return $result;
}

Expand All @@ -882,11 +914,20 @@ public static function newFromArray(
float $scale = 1.0,
float $offset = 0.0
): Image {
Utils::debugLog('newFromArray', [
'instance' => null,
'arguments' => [$array, $scale, $offset]
]);

$result = vips_image_new_from_array($array, $scale, $offset);
if ($result === -1) {
self::errorVips();
}
return self::wrapResult($result);
$result = self::wrapResult($result);

Utils::debugLog('newFromArray', ['result' => $result]);

return $result;
}

/**
Expand All @@ -905,6 +946,11 @@ public static function newFromArray(
*/
public static function newInterpolator(string $name)
{
Utils::debugLog('newInterpolator', [
'instance' => null,
'arguments' => [$name]
]);

// added in 1.0.7 of the binary module
return vips_interpolate_new($name);
}
Expand All @@ -925,6 +971,11 @@ public static function newInterpolator(string $name)
*/
public function newFromImage($value): Image
{
Utils::debugLog('newFromImage', [
'instance' => $this,
'arguments' => [$value]
]);

$pixel = self::black(1, 1)->add($value)->cast($this->format);
$image = $pixel->embed(
0,
Expand All @@ -936,11 +987,13 @@ public function newFromImage($value): Image
$image = $image->copy([
'interpretation' => $this->interpretation,
'xres' => $this->xres,
'yres' => $this->yres,
'yres' => $this->yres,
'xoffset' => $this->xoffset,
'yoffset' => $this->yoffset
]);

Utils::debugLog('newFromImage', ['result' => $image]);

return $image;
}

Expand All @@ -955,6 +1008,11 @@ public function newFromImage($value): Image
*/
public function writeToFile(string $filename, array $options = [])
{
Utils::debugLog('writeToFile', [
'instance' => $this,
'arguments' => [$filename, $options]
]);

$options = self::unwrap($options);
$result = vips_image_write_to_file($this->image, $filename, $options);
if ($result === -1) {
Expand All @@ -973,12 +1031,21 @@ public function writeToFile(string $filename, array $options = [])
*/
public function writeToBuffer(string $suffix, array $options = []): string
{
Utils::debugLog('writeToBuffer', [
'instance' => $this,
'arguments' => [$suffix, $options]
]);

$options = self::unwrap($options);
$result = vips_image_write_to_buffer($this->image, $suffix, $options);
if ($result === -1) {
self::errorVips();
}
return self::wrapResult($result);
$result = self::wrapResult($result);

Utils::debugLog('writeToBuffer', ['result' => $result]);

return $result;
}

/**
Expand All @@ -995,11 +1062,20 @@ public function writeToBuffer(string $suffix, array $options = []): string
*/
public function copyMemory(): Image
{
Utils::debugLog('copyMemory', [
'instance' => $this,
'arguments' => []
]);

$result = vips_image_copy_memory($this->image);
if ($result === -1) {
self::errorVips();
}
return self::wrapResult($result);
$result = self::wrapResult($result);

Utils::debugLog('copyMemory', ['result' => $result]);

return $result;
}

/**
Expand Down Expand Up @@ -1148,10 +1224,10 @@ public static function callBase(
$instance,
array $arguments
) {
Utils::debugLog(
$name,
['instance' => $instance, 'arguments' => $arguments]
);
Utils::debugLog($name, [
'instance' => $instance,
'arguments' => $arguments
]);

$arguments = array_merge([$name, $instance], $arguments);

Expand Down Expand Up @@ -1265,7 +1341,7 @@ public function hasAlpha(): bool
{
return $this->bands === 2 ||
($this->bands === 4 &&
$this->interpretation !== Interpretation::CMYK) ||
$this->interpretation !== Interpretation::CMYK) ||
$this->bands > 4;
}

Expand Down