Jump to content
horst

Page Image Manipulator 1

Recommended Posts

The next version of PiM will be able to enhance the Thumbnails module

(after I have successful send a pull request to apeisa and he have had time to check and implement the code, - hopefully)
 
 
While writing on the (optional) support for PiM with Thumbnails, owzim has written the js-code that rebuilds the crop rectangle, - and also he has tested and forthrightly commented my various tests with that. ^-^
 
Thumbnails will recognize if PiM is installed and use a different routine then. And without PiM the Thumbnails Module will use the PW core ImageSizer. Since dev-version 2.3.3 the ImageSizer uses automatic sharpening after resize. So - once after updating to the new module and a newer PW version (dev 2.3.3 or stable 2.4) everyone has sharpening support. :)

We both (owzim & me) want to have the coords & data stored and pre-selected when coming back to a previous created thumbnail. We use a wrapper class with a read and a write method on a session basis to achieve that. (After closing the browser or otherwise destroy the session, all data is lost)
 
But together with PiM the coords and options can be stored permanent! It can be stored as metadata in a IPTC custom field (2#215) with the original imagefile. :)

If you want enable permanent storage you have to create a config array named imageManipulatorOptions in your site/config.php and create the key thumbnailCoordsPermanent and set it to true:

$config->imageManipulatorOptions = array(
   // ...
	'thumbnailCoordsPermanent' => true
);

So, - if you don't want permanent storage, you are still able to use Thumbnails Module and PiM together, but without permanent storage.


 
https://youtu.be/IHwjL7YSfRo
 

EDIT: PullRequest is send https://github.com/apeisa/Thumbnails/pull/13 (the unorthodox way) :P

Edited by horst
  • Like 6

Share this post


Link to post
Share on other sites

No way thats not possible !!!

Very impressive !!!

Big tnx @Horst

oh, it's possible because of the help from owzim!

so it should be: "Big tnx @owzim, too" :)

  • Like 2

Share this post


Link to post
Share on other sites

@horst Thanks for the explanation. Maybe it's also ok if you mention the transparency range in your documentation so it's not necessary to change the code ;-)

Share this post


Link to post
Share on other sites

@horst Thanks for the explanation. Maybe it's also ok if you mention the transparency range in your documentation so it's not necessary to change the code ;-)

I have had to rewrite it because the alpha transparency wasn't supported at all.

I just have pushed the version 0.0.8 to GitHub. :)

post-1041-0-15209900-1378060978_thumb.jp

There are some other fixes and changes with the version 0.0.8:

  • added enhanced support for Thumbnails module, including permanent storage for CropRectangleCoords and params
  • fixed / rewritten all bg-color stuff to support rgba alpha channel
  • fixed a E-Notice with IPTC prepare
  • changed the params of method resize, width, height to be the same like in new ImageSizer, ($sharpen can have value 'none')

I will also update the first post of this thread.

  • Like 4

Share this post


Link to post
Share on other sites

@Marty: thanks! Have you seen the post about PiM working together with Thumbnails too? I think you will like it! At least you are responsible for the existence of the Thumbnails Module. ^-^  ( and yes, - Antti  ^-^  is responsible too)

I'm very new and inexpertly with GitHub, because of that I have asked owzim if he can help me to send a pull request to Thumbnails repo with only code for sharpening support. While talking/writing about that GitHub stuff - we also come to conclusion that Thumbnails needs recreation of previously used thumbs. And as I don't know the JS stuff, owzim seems to know it very well and he wrote it! ^-^

I really like that community here and also how good people work together to make things good and better. ^-^

Thank you!

  • Like 4

Share this post


Link to post
Share on other sites

Hi Horst,

Trying to create a gif from a PNG 24. 

echo $img->name; // image.png

$info = $img->pimLoad("test", true)->getImageInfo();
var_dump($info);

// array(11) {
//   ["type"]=> string(3) "png"
//   ["imageType"]=> int(3)
//   ["mimetype"]=> string(9) "image/png"
//   ["width"]=> int(114)
//   ["height"]=> int(48)
//   ["landscape"]=> bool(true)
//   ["ratio"]=> float(2,375)
//   ["bits"]=> int(8)
//   ["channels"]=> int(6)
//   ["colspace"]=> string(9) "DeviceRGB"
//   ["alpha"]=> bool(true)
// }

$pim = $img->pimLoad("test", true)->pimSave();
Warning:  imagealphablending() expects parameter 1 to be resource, null given in /path/to/htdocs/site/modules/PageImageManipulator/ImageManipulator.class.php on line 684

$pim = $img->pimLoad("test", true)->setOutputFormat("gif")->pimSave();
Warning:  imagegif() expects parameter 1 to be resource, null given in /path/to/htdocs/site/modules/PageImageManipulator/ImageManipulator.class.php on line 681

$pim = $img->pimLoad("test")->setOptions(array("outputFormat" => "gif"))->pimSave();
Warning:  imagegif() expects parameter 1 to be resource, null given in /path/to/site/modules/PageImageManipulator/ImageManipulator.class.php on line 681

Share this post


Link to post
Share on other sites

Hi Martijn,

sorry, in a previous version this has worked, but by rewriting for rgba support I must have broken it. I have pushed an update to github that solved the issue.

But I think the result from converting transparent png to gif isn't what you expect :( 

Because transparency get not transformed into GIF-Palette-Color. It seems this isn't possible, - at least not that simple. ??

But bug is fixed now, thanks for your help!

Share this post


Link to post
Share on other sites

Hi Horst, 

TNX for your followup & bug fix.

<horst>But I think the result from converting transparent png to gif isn't what you expect :(</horst>

Is it possible to create a jpeg from the PNG 24 attach a background form a variable value [ rgb(100,100,100) ] then scale it and save it to gif ?

( want to use it in for newsletters )

Share this post


Link to post
Share on other sites

Hi Martijn,

can you only use gif? (Newsletter with embedded cid: ?)

You may try:

function pimPng2Gif($im1, $rgb) {
	imagealphablending($im1, true);
	imagesavealpha($im1, false);
	$w = imagesx($im1);
	$h = imagesy($im1);
	$im2 = imagecreatetruecolor($w, $h);
	imagealphablending($im2, true);
	imagesavealpha($im2, false);
	$bg = imagecolorallocate($im2, $rgb[0], $rgb[1], $rgb[2]);
	imagefilledrectangle($im2,0,0,$w-1,$h-1,$bg);
	imagecopy($im2,$im1,0,0,0,0,$w,$h);
	imagedestroy($im1);
	return $im2;
}

$rgb = array(219,17,116);

$png = $page->images->first()->pimLoad('png2gif',true);
$gif = $png->setMemoryImage( pimPng2Gif($png->getMemoryImage(), $rgb) )->setOutputformat('gif')->save();

echo "<img src='{$gif->url}' /> {$gif->name}";

Edited by horst
  • Like 1

Share this post


Link to post
Share on other sites

Tnx Horst, great !

Yep can only use gif. ( newsletter build system :))

Left the office earlier today, was to tired to think. Gonna try it tomorrow !

Share this post


Link to post
Share on other sites

Hi guys, im totaly new to PHP and i cant figure out what im doing wrong here :

<ul>
	<?php
		$news = $pages->find("parent=1009");
		$out =" ";
		foreach($news as $news){
			$pageimage = $news->images->first->width(313)->pimLoad('news')->pimSave()->url;
			$out .= "<li><a href='{$news->url}'>";
			$out .= "<img src='{$pageimage}' alt='' />";
			$out .= "{$news->title}";
			$out .= "{$news->body}";
			$out .= date("j.m.Y", $news->created);
			$out .= "</a></li>";
		}
	echo $out;
 ?>
</ul>

and here is my error:
 

<p class="error WireFatalError">
Error: Call to a member function width() on a non-object (line 9 of D:\xampp\htdocs\projects\chemik\site\templates\home\news.html)
<br>
<br>
<em>This error message was shown because you are logged in as a Superuser. Error has been logged. </em>

Ty.
 

Share this post


Link to post
Share on other sites
foreach($news as $news){

On this line you are overriding the array news, by assigning the individual item to it. Change one of those variables to something different. Don't forget to change all occurrences of it.

  • Like 1

Share this post


Link to post
Share on other sites

@vxda:  and of course, for resizing you don't need the Pageimage Manipulator. It is enough to call ->width() on a pageimage:

// example
$pageimage = $myNewsItem->images->first->width(313)->url;

But also your variable names are a bit confusing: your variable $pageimage contains only the URL. I would change this to avoid confusion:

// example
$pageimage = $myNewsItem->images->first->width(313);

// and then
$out .= "<img src='{$pageimage->url}' alt='' />";

References on how to work with images:

Edited by horst
  • Like 1

Share this post


Link to post
Share on other sites

@horst:
Ty for a quick reply.

i changed my code to this

<?php
	$news = $pages->find("parent=1009");
	$out ="";
	foreach($news as $newsitem){
		$newsimg = $newsitem->images->first->width(313);
		$out .= "<li><a href='{$newsitem->url}'>";
		$out .= "<img src='{$newsimg->url}' alt='' />";
		$out .= "{$newsitem->title}";
		$out .= "{$newsitem->body}";
		$out .= date("j.m.Y", $newsitem->created);
		$out .= "</a></li>";
	}
	echo $out;
 ?>

and i still have this error.

when i remove

->width(313)

it picks the right picture and it all works, but without resizing img.

what am i missing ?

Thank you

Share this post


Link to post
Share on other sites

Ok i got it ;) problem solved

adding:

if ($newsimg) {
	$newsimg = $newsimg->size(313,177)->url;
}

solved the problem so my code looks like this now :

<?php
				$news = $pages->find("parent=1009");
				$out ="";
					foreach($news as $newsitem){
						$newsimg = $newsitem->images->first;
						if ($newsimg) {
							$newsimg = $newsimg->size(313,177)->url;
						}
						$out .= "<li><div><a href='{$newsitem->url}'>";
						$out .= "<img src='{$newsimg}' alt='' />";

						$out .= "{$newsitem->title}";
						$out .= "{$newsitem->body}";
						$out .= date("j.m.Y", $newsitem->created);
						$out .= "</a></div></li>";
					}
					echo $out;
				 ?>

Thank you for help.

  • Like 1

Share this post


Link to post
Share on other sites

vxda glad you figured it out.

It's always good to check if there's images, you could also use count(), and maybe also not output the image if there's no image.

So you could also do

...
$out .= "<li><div><a href='{$newsitem->url}'>";
if ($newsitem->images->count()) {
   $out .= "<img src='{$newsitem->images->first->size(313,177)->url}'/>";
}
$out .= "{$newsitem->title}";
...
  • Like 1

Share this post


Link to post
Share on other sites

First one is nicer to look at (in my opinion). I don't believe there is real difference.

Share this post


Link to post
Share on other sites

Hi Horst,

thanks for this really impressive module. It's a dream (even the watermarking is important for me).

I have one problem.

I often have to delete images and replace with newer ones.

But then i get a large amount of orphaned pim-image-files in my page assets folders.

A solution was mentioned here:

http://processwire.com/talk/topic/4437-delete-orphaned-filesimages-from-siteassetsfiles/

But isn't there a way to delete the appropriate pim-image-file(s) automatically when deleting the original pw-image-file ?

Greetings,

Wolf

Share this post


Link to post
Share on other sites

... But isn't there a way to delete the appropriate pim-image-file(s) automatically when deleting the original pw-image-file ?

Actually you only can use the method removePimVariations() on a per image base to delete all your testfiles!

$img = $page->images->first();

$img->pimLoad('prefix')->removePimVariations();

and they all are gone.

But automaticly delete them when deleting a original image isn't supported yet. At least if you delete them manually in the backend. If you delete them via the API, there should be a simple way / workaround to get it solved. How do you delete them?

When deleteing images manually in the backend:

If you really have much changes and therefor a lot of orphaned files, you may use the lazycron module (core, but you have to install it first) together with the delete-orphaned-files script.

It would be much better to get rid of that automaticly as you said, but I need to find the way how to do it. And within next weeks there are no time available for extending PiM. :(

Edited by horst

Share this post


Link to post
Share on other sites

Today I have added a hook to the module that add pim_* variations to pageimage-variation-collection.

This is usefull to not have mass orphaned (pim_)images on the disk when original images got deleted.

I have had this code ready for many weeks and would have done some more (workaround for GDlibs buggy sharpening on pngs with alpha-transparency) before update the module. But I haven't had time for this.

So, there are no other changes in module version 0.1.1 what is available now at github and in the modules section.

Cheers!

  • Like 3

Share this post


Link to post
Share on other sites

Thank you, Horst, for this great module.

Bug report: the ratio isn't calculated correctly.

Two lines containing:

'ratio'	   => floatval(($info[0]>=$info[1] ? $info[0]/$info[1] : $info[1]/$info[2]))

have to be:

'ratio'	   => floatval(($info[0]>=$info[1] ? $info[0]/$info[1] : $info[1]/$info[0]))
  • Like 2

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By eelkenet
      Hi! I've created a small Inputfield module called InputfieldFloatRange which allows you to use an HTML5 <input type="range" ../> slider as an InputField. I needed something like this for a project where the client needs to be able to tweak this value more based on 'a feeling' than just entering a boring old number. Maybe more people can use this so I'm hereby releasing it into the wild. 
      EDIT: You can now install it directly from the Modules directory: http://modules.processwire.com/modules/inputfield-float-range/
       
      What is it?
      The missing range slider Inputfield for Processwire. 
      What does it do?
      This module extends InputfieldFloat and allows you to use HTML5 range sliders for number fields in your templates.
      It includes a visible and editable value field, to override/tweak the value if required.  
      Features
      Min/max values Precision (number of decimals) Optional step value (Read more) Optional manual override of the selected value (will still adhere to the rules above) Configurable rounding of manually entered values (floor, round, ceil, disable) Usage
      Clone / zip repo Install FieldtypeFloatRange, this automatically installs the Inputfield Create new field of type `Float (range)` or convert an existing `Float`, `Integer` or `Text` field. To render the field's value simply echo `$page->field` Demo
      A field with Min=0, Max=1, Step=0.2, Precision=2

      Field with settings Min=0, Max=200, Step=0.25, Precision=2

       
      Todo
      Make the display-field's size configurable (will use the Input Size field setting)  Hopefully become redundant  
      Changelog
      004 (current version)
      - Make rounding of manually entered values configurable (floor, round, ceil or disable)
      - Fix small JS bug when the value-display field was not displayed
      - Update README
      003
      - Code cleanup, add some ModuleInfo data & LICENSE
      - Submit to PW Modules directory (http://modules.processwire.com/modules/inputfield-float-range/)
      002
      - Fix issue where setting the step value to an empty value created problem with validation
      - Make the display-field optional
      001
      - Initial release
       
      Thanks!
       
       
    • By Gadgetto
      Status update links (inside this thread) for SnipWire development will be always posted here:
      2019-10-18
      2019-08-08
      2019-06-15
      2019-06-02
      2019-05-25
      If you are interested, you can test the current state of development:
      https://github.com/gadgetto/SnipWire
      Please note that the software is not yet intended for use in a production system (alpha version).
      If you like, you can also submit feature requests and suggestions for improvement. I also accept pull requests.
      ---- INITIAL POST FROM 2019-05-25 ----
      I wanted to let you know that I am currently working on a new ProcessWire module that fully integrates the Snipcart Shopping Cart System into ProcessWire. (this is a customer project, so I had to postpone the development of my other module GroupMailer).
      The new module SnipWire offers full integration of the Snipcart Shopping Cart System into ProcessWire.
      Here are some highlights:
      simple setup with (optional) pre-installed templates, product fields, sample products (quasi a complete shop system to get started immediately) store dashboard with all data from the snipcart system (no change to the snipcart dashboard itself required) Integrated REST API for controlling and querying snipcart data webhooks to trigger events from Snipcart (new order, new customer, etc.) multi currency support self-defined/configurable tax rates etc. Development is already well advanced and I plan to release the module in the next 2-3 months.
      I'm not sure yet if this will be a "Pro" module or if it will be made available for free.
      I would be grateful for suggestions and hints!
      (please have a look at the screenshots to get an idea what I'm talking about)
       




    • By Robin S
      Another little admin helper module...
      Template Field Widths
      Adds a "Field widths" field to Edit Template that allows you to quickly set the widths of inputfields in the template.

      Why?
      When setting up a new template or trying out different field layouts I find it a bit slow and tedious to have to open each field individually in a modal just to set the width. This module speeds up the process.
      Installation
      Install the Template Field Widths module.
      Config options
      You can set the default presentation of the "Field widths" field to collapsed or open. Field widths entered into the Template Field Widths inputfield are only applied if the Edit Template form is submitted with the Template Field Widths inputfield in an opened state. "Collapsed" is the recommended setting if you think you might also use core inputs for setting field widths in a template context. You can choose Name or Label as the primary identifier shown for the field. The unchosen alternative will become the title attribute shown on hover. You can choose to show the original field width next to the template context field width.  
      https://github.com/Toutouwai/TemplateFieldWidths
      https://modules.processwire.com/modules/template-field-widths/
    • By NehaPillai
      Hello Everyone, I was trying to update SEO meta title, description and meta keywords for my website in Process Wire CMS but it saving in the backend but it is not reflecting on my website, Please help me regarding this error. Please find below attached screen shot for your ref. TIA.


    • By adrian
      Tracy Debugger for ProcessWire
      The ultimate “swiss army knife” debugging and development tool for the ProcessWire CMF/CMS

       
      Integrates and extends Nette's Tracy debugging tool and adds 35+ custom tools designed for effective ProcessWire debugging and lightning fast development
      The most comprehensive set of instructions and examples is available at: https://adrianbj.github.io/TracyDebugger
      Modules Directory: http://modules.processwire.com/modules/tracy-debugger/
      Github: https://github.com/adrianbj/TracyDebugger
      A big thanks to @tpr for introducing me to Tracy and for the idea for this module and for significant feedback, testing, and feature suggestions.
×
×
  • Create New...