php-vips: writeToBuffer doesn't output edited/removed EXIF data

Testcase: https://gist.github.com/kleisauke/5a9272198172fc95a47b9add54b0189d

Test image: https://raw.githubusercontent.com/recurser/exif-orientation-examples/master/Landscape_6.jpg

php test.php Landscape_6.jpg

Should output:

Rotate 90 degrees
No EXIF Orientation
No EXIF Orientation

Instead the original orientation is outputted:

Rotate 90 degrees
No EXIF Orientation
Rotate 90 degrees

By the way, Maybe it’s better to also include the vips_image_get_typeof in this PHP binding (for example $image->get_typeof($fieldName);). I’m now catching exceptions instead.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 31 (31 by maintainers)

Commits related to this issue

Most upvoted comments

Here it is in PHP:

#!/usr/bin/env php
<?php

require __DIR__ . '/vendor/autoload.php';

use Jcupitt\Vips;

function sigmoid(bool $sharpen, float $midpoint, float $contrast,
    bool $ushort = false): Vips\Image
{   
    $lut = Vips\Image::identity(["ushort" => $ushort]);
    // Rescale so each element is in [0, 1]
    $range = $lut->max();
    $lut = $lut->divide($range);

    if ($sharpen) {
        $x = $lut->multiply(-1)->add($midpoint)->multiply($contrast)->
            exp()->add(1)->pow(-1);
        $min = $x->min();
        $max = $x->max();
        $result = $x->subtract($min)->divide($max - $min);
    } else { 
        $min = 1 / (1 + exp($contrast * $midpoint)); 
        $max = 1 / (1 + exp($contrast * ($midpoint - 1)));
        $x = $lut->multiply($max - $min)->add($min);
        $result = $x->multiply(-1)->add(1)->divide($x)->log()->
            divide($contrast)->multiply(-1)->add($midpoint);
    }

    // Rescale back to 0 - 255 or 0 - 65535
    $result = $result->multiply($range);
    $result = $result->cast($ushort ? 
        Vips\BandFormat::USHORT : Vips\BandFormat::UCHAR);

    return $result;
}

$midpoint = 0.5;
$contrast = 6;

$sig = sigmoid(TRUE, $midpoint, $contrast);
$sig->writeToFile("x1.v");

$sig = sigmoid(FALSE, $midpoint, $contrast);
$sig->writeToFile("x2.v");

Run nip2 x*.v to see the two curves.

That’s a very direct translation. You can make it a bit quicker: there are several sequences like:

$x->multiply(-1)->add($midpoint)->multiply($contrast)->...

That’s a simple linear transform of $x, so you can swap those three calls for a single ->linear(). Of course this is just making a LUT and won’t be run for every pixel, so perhaps speed doesn’t matter.

OK, I’ve updated everything with the fixed equation, it works much better now, though you can no longer decrease contrast.

I’ll have a look at the IM sources and see how they do contrast reduction.