Jump to content

Page Image Manipulator | API for 1 & 2


horst

Recommended Posts

Ok I have it corrected but still it doesn't work. No error, no new image created.

$p = wire("pages")->get(1111);
echo $p->image->url;
$img = $p->image;
$pim = $img->pimLoad("bright")->contrast(100)->brightness(100)->pimSave();
echo "<img src='$pim->url'/>";
 
Link to comment
Share on other sites

Ok I have it corrected but still it doesn't work. No error, no new image created.

$p = wire("pages")->get(1111);
echo $p->image->url;
$img = $p->image;
$pim = $img->pimLoad("bright")->contrast(100)->brightness(100)->pimSave();
echo "<img src='$pim->url'/>"; 

hhm, very mysterious. When I use your code I get a new image!

I assume you have get the latest version of the module, tried a new install already?

What do you get when you use:

$p = wire("pages")->get(1111);
$img = $p->image;

echo '<p>' . $img->url .'</p>';
echo '<p>' . $img->width(240)->url .'</p>';   // does the imageSizer work with that image?

echo '<pre>';
	var_dump($img->pimLoad("bright")->getImageInfo());  // what is the output here
echo '</pre>';
Link to comment
Share on other sites

No there's no image created and it silently fails, means code after doing the image doesn't get executed at all.

I tried locally and it works, so it's the server I'm working on... although it's php 5.3 and GD 2...

Link to comment
Share on other sites

It doesn't do anything. :)

Ok strange, now it works, and I only added some echo "test" inside the getPageImageManipulator() and uploaded. 

So I think I got when testing added a exit() there and haven't uploaded the module when removing it. Darn. :) Thanks for your time.

  • Like 1
Link to comment
Share on other sites

Q: How could I easily replace the original pageimage keeping same filename?

with a pageimage loaded into the {Pageimage} {Manipulator} you are not able to overwrite the original!

You have to use the {Image} {Manipulator} manually with a filename. Here you can do everything you want, - or the opposite: you alone are fully responsible for _all_ actions, ;-)

$pim = $wire->modules->get('PageImageManipulator')->imLoad($imageFilename, $options);  // here it is used imLoad = image manipulator instead of page image manipulator

If you do not specify an alternate filename or outputFormat with the options array, the sourcefile loaded into the IM is overwritten by default!

Note: if you overwrite your original image, you wipe out all EXIF-data, whereas all IPTC-data is kept!

-------------

Hey Soma, it looks like you are building a visual Photo-Editor based on PW.  cool!

  • Like 1
Link to comment
Share on other sites

Greetings,

Horst, would you consider adding a resize mode that adds a colored or transparent padding instead of distorting the image? Something like this:

That would be great!

I can't even count how many client photos I have had to edit manually in this way so they look correct in my galleries.

Thanks,

Matthew

Link to comment
Share on other sites

Horst, would you consider adding a resize mode that adds a colored or transparent padding instead of distorting the image? Something like this:

attachicon.gifmarquis_interior3_bvnesu_amarelo.jpg

attachicon.gifmarquis_interior3_bvnesu_verde.jpg

Hi diogo, if you believe it or not, I have thought about this allready. And I have something like this in an old image lib of mine. I will look at that code and port it to the IM.

I think best way is to define dimensions of a canvas in that the previous created image is centered. That way one can get only the horizontal or only the the vertical bars, or surrounding ones.

Link to comment
Share on other sites

Great!

I think it could be even more complex than that. Ideally it would have these options:

  • width
  • height
  • background-color (including the possibility of rgba if possible)
  • x-position
  • y-position

Does it make sense like this?

Link to comment
Share on other sites

Great!

I think it could be even more complex than that. Ideally it would have these options:

  • width
  • height
  • background-color (including the possibility of rgba if possible)
  • x-position
  • y-position

Does it make sense like this?

@diogo: width & height & BG as rgba is ok!

But for what is x- and y-position?

I have thought one want to center it into the canvas.

If you think it make sence to position out of the center, I think it could be better to use the north, northwest, center, etc position and a $padding (I would prefer in percent), that would be most consistent way with other methods.

What do you think?

Link to comment
Share on other sites

hoi, there are now two 'unplanned' additions in the Version 0.0.5:
 
canvas($width, $height, $bgcolor, $position, $padding)

  • $width = mixed, associative array with options or integer, mandatory!
  • $height = integer, mandatory if $width is integer!
  • $bgcolor = array with rgb or rgba, - default is 255, 255, 255
  • $position = one out of north, northwest, center, etc, - default is center
  • $padding = integer as percent of canvas length, - default is 0

pw_pim_canvas.jpg
 


unsharpMask($amount=100, $radius=0.5, $threshold=3) // its the same like the method in Photoshop,
credit goes to: Torstein Hønsi for the unsharp mask algorithm (created in 2003 - p h p U n s h a r p M a s k)!


pw_pim_unsharpMask.jpg

..., can create better results than the default stepResize!

  • Like 2
Link to comment
Share on other sites

So there's a ton of functions and filter but auto-levels http://www.imagemagick.org/script/command-line-options.php#auto-level there's nothing in GD? ... :D

Other then in imagemagick, i don't see a ton of functions and filters in there :D

I think to autoadjust something there is always a portion of guessing with it - or 'out-rider' pixels that screw up or down the autoadjusted result into false directions.

I never use such tools without a manually visually control. Also with captureOne and photoshop I do not use those with batch editing.

Link to comment
Share on other sites

  • 2 weeks later...

Hi Horst, your plugin is great and the canvas addition is superb ;-)

However ... I have there a little problem with the canvas addition. 

The call of

child->image2->pimLoad('wh',true)->canvas(195,193,array(0,0,0,0.0),"centered",0)->pimSave()->url;

returns me the image with a black border. I want it transparent. Is there something I missed?

TIA

Henning

Link to comment
Share on other sites

Hi Henning,

I think you have the wrong param for opacity. PHP.net says:

function imagecolorallocatealpha

  param alpha:
      A value between 0 and 127. 0 indicates completely opaque while 127 indicates completely transparent.

Please try with

child->image2->pimLoad('wh', true)->canvas(195, 193, array(0, 0, 0, 127), "centered", 0)->pimSave()->url;

EDIT:

@Henning: I have noticed that the common way to define a rgba color is 0-255 for R, G and B and a float value between 0 and 1 for the alpha channel (opacity). 0 is transparent and 1 is opaque.

I think it is better to use the common way with float 0-1 as param and convert it internally to suite the need of the GD-lib.

The change will go into the module version 0.0.8 and I will release it later this weekend.

Edited by horst
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...