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 Robin S
      Repeater Images
      Adds options to modify Repeater fields to make them convenient for "page-per-image" usage. Using a page-per-image approach allows for additional fields to be associated with each image, to record things such as photographer, date, license, links, etc.
      When Repeater Images is enabled for a Repeater field the module changes the appearance of the Repeater inputfield to be similar (but not identical) to an Images field. The collapsed view shows a thumbnail for each Repeater item, and items can be expanded for field editing.
      Screencast

      Installation
      Install the Repeater Images module.
      Setup
      Create an image field to use in the Repeater field. Recommended settings for the image field are "Maximum files allowed" set to 1 and "Formatted value" set to "Single item (null if empty)". Create a Repeater field. Add the image field to the Repeater. If you want additional fields in the Repeater create and add these also. Repeater Images configuration
      Tick the "Activate Repeater Images for this Repeater field" checkbox. In the "Image field within Repeater" dropdown select the single image field. You must save the Repeater field settings to see any newly added Image fields in the dropdown. Adjust the image thumbnail height if you want (unlike the core Images field there is no slider to change thumbnail height within Page Edit). Note: the depth option for Repeater fields is not compatible with the Repeater Images module.
      Image uploads feature
      There is a checkbox to activate image uploads. This feature allows users to quickly and easily add images to the Repeater Images field by uploading them to an adjacent "upload" field.
      To use this feature you must add the image field selected in the Repeater Images config to the template of the page containing the Repeater Images field - immediately above or below the Repeater Images field would be a good position.
      It's recommended to set the label for this field in template context to "Upload images" or similar, and set the visibility of the field to "Closed" so that it takes up less room when it's not being used. Note that when you drag images to a closed Images field it will automatically open. You don't need to worry about the "Maximum files allowed" setting because the Repeater Images module overrides this for the upload field.
      New Repeater items will be created from the images uploaded to the upload field when the page is saved. The user can add descriptions and tags to the images while they are still in the upload field and these will be retained in the Repeater items. Images are automatically deleted from the upload field when the page is saved.
      Tips
      The "Use accordion mode?" option in the Repeater field settings is useful for keeping the inputfield compact, with only one image item open for editing at a time. The "Repeater item labels" setting determines what is shown in the thumbnail overlay on hover. Example for an image field named "image": {image.basename} ({image.width}x{image.height})  
      https://github.com/Toutouwai/RepeaterImages
      https://modules.processwire.com/modules/repeater-images/
    • By EyeDentify
      Hello There Guys.

      I am in the process of getting into making my first modules for PW and i had a question for you PHP and PW gurus in here.

      I was wondering how i could use an external library, lets say TwitterOAuth in my PW module.
      Link to library
      https://twitteroauth.com/

      Would the code below be correct or how would i go about this:
      <?PHP namespace ProcessWire; /* load the TwitterOAuth library from my Module folder */ require "twitteroauth/autoload.php"; use Abraham\TwitterOAuth\TwitterOAuth; class EyeTwitter extends WireData,TwitterOAuth implements Module { /* vars */ protected $twConnection; /* extend parent TwitterOAuth contructor $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token, $access_token_secret); */ public function myTwitterConnection ($consumer_key, $consumer_secret, $access_token, $access_token_secret) { /* save the connection for use later */ $this->twConnection = TwitterOAuth::__construct($consumer_key, $consumer_secret, $access_token, $access_token_secret); } } ?> Am i on the right trail here or i am barking up the wrong tree?
      I don´t need a complete solution, i just wonder if i am including the external library the right way.
      If not, then give me a few hint´s and i will figure it out.

      Thanks a bunch.

      /EyeDentify
    • By dimitrios
      Hello,
      this module can publish content of a Processwire page on a Facebook page, triggered by saving the Processwire page.
      To set it up, configure the module with a Facebook app ID, secret and a Page ID. Following is additional configuration on Facebook for developers:
      Minimum Required Facebook App configuration:
      on Settings -> Basics, provide the App Domains, provide the Site URL, on Settings -> Advanced, set the API version (has been tested up to v3.3), add Product: Facebook Login, on Facebook Login -> Settings, set Client OAuth Login: Yes, set Web OAuth Login: Yes, set Enforce HTTPS: Yes, add "http://www.example.com/processwire/page/" to field Valid OAuth Redirect URIs. This module is configurable as follows:
      Templates: posts can take place only for pages with the defined templates. On/Off switch: specify a checkbox field that will not allow the post if checked. Specify a message and/or an image for the post.
      Usage
      edit the desired PW page and save; it will post right after the initial Facebook log in and permission granting. After that, an access token is kept.
       
      Download
      PW module directory: http://modules.processwire.com/modules/auto-fb-post/ Github: https://github.com/kastrind/AutoFbPost   Note: Facebook SDK for PHP is utilized.


    • By kongondo
      FieldtypeRuntimeMarkup and InputfieldRuntimeMarkup
       
      Modules Directory: http://modules.processwire.com/modules/fieldtype-runtime-markup/
      GitHub: https://github.com/kongondo/FieldtypeRuntimeMarkup
      As of 11 May 2019 ProcessWire versions earlier than 3.x are not supported
      This module allows for custom markup to be dynamically (PHP) generated and output within a page's edit screen (in Admin).
       
      The value for the fieldtype is generated at runtime. No data is saved in the database. The accompanying InputfieldRuntimeMarkup is only used to render/display the markup in the page edit screen.
       
      The field's value is accessible from the ProcessWire API in the frontend like any other field, i.e. it has access to $page and $pages.
       
      The module was commissioned/sponsored by @Valan. Although there's certainly other ways to achieve what this module does, it offers a dynamic and flexible alternative to generating your own markup in a page's edit screen whilst also allowing access to that markup in the frontend. Thanks Valan!
       
      Warning/Consideration
      Although access to ProcessWire's Fields' admin pages is only available to Superusers, this Fieldtype will evaluate and run the custom PHP Code entered and saved in the field's settings (Details tab). Utmost care should therefore be taken in making sure your code does not perform any CRUD operations!! (unless of course that's intentional) The value for this fieldtype is generated at runtime and thus no data is stored in the database. This means that you cannot directly query a RuntimeMarkup field from $pages->find(). Usage and API
       
      Backend
      Enter your custom PHP snippet in the Details tab of your field (it is RECOMMENDED though that you use wireRenderFile() instead. See example below). Your code can be as simple or as complicated as you want as long as in the end you return a value that is not an array or an object or anything other than a string/integer.
       
      FieldtypeRuntimeMarkup has access to $page (the current page being edited/viewed) and $pages. 
       
      A very simple example.
      return 'Hello'; Simple example.
      return $page->title; Simple example with markup.
      return '<h2>' . $page->title . '</h2>'; Another simple example with markup.
      $out = '<h1>hello '; $out .= $page->title; $out .= '</h1>'; return $out; A more advanced example.
      $p = $pages->get('/about-us/')->child('sort=random'); return '<p>' . $p->title . '</p>'; An even more complex example.
      $str =''; if($page->name == 'about-us') { $p = $page->children->last(); $str = "<h2><a href='{$p->url}'>{$p->title}</a></h2>"; } else { $str = "<h2><a href='{$page->url}'>{$page->title}</a></h2>"; } return $str; Rather than type your code directly in the Details tab of the field, it is highly recommended that you placed all your code in an external file and call that file using the core wireRenderFile() method. Taking this approach means you will be able to edit your code in your favourite text editor. It also means you will be able to type more text without having to scroll. Editing the file is also easier than editing the field. To use this approach, simply do:
      return wireRenderFile('name-of-file');// file will be in /site/templates/ If using ProcessWire 3.x, you will need to use namespace as follows:
      return ProcessWire\wireRenderFile('name-of-file'); How to access the value of RuntimeMarkup in the frontend (our field is called 'runtime_markup')
       
      Access the field on the current page (just like any other field)
      echo $page->runtime_markup; Access the field on another page
      echo $pages->get('/about-us/')->runtime_markup; Screenshots
       
      Backend
       

       

       
      Frontend
       

×
×
  • Create New...