Recommended Posts

Does anybody know why I am unable to debug images? I only see the field name, but not the array with the list of images, I tried xdebug and tracy debugger...

This is my code: var_dumb($page->fields) or dumbAll($page->fields).
This is what I see, note that I have several images (array) in this page:

img_004.jpg


If I try foreach on the fieldgroup and output the fieldname I can get the image url...

P.S. a little bit off topic...but is there a way to just get the data/values of the fields? I don't really care about all the other fields like hooks, wire, notices, etc etc...

Share this post


Link to post
Share on other sites

Then again, if you have Tracy, then look at the PW Info panel and the "Field List & Values" section and you'll get a nicely formatted array, like this:

Screen Shot 2016-11-10 at 7.05.56 PM.png

  • Like 3

Share this post


Link to post
Share on other sites

My setup is a little bit confusing, in the "Field List & Values" of ProcessWire popup, I see the following (only "title" field!):

img_005.jpg

If I try to output da($p->banners->toArray()); I get this list, without the array:
img_010.jpg

If I try foreach ($p->banners as $banner) {da($banner); } I get this (and here the strange thing is that the imgs have no width/height, url, httpurl etc). Do you have any idea of what I am doing wrong?

img_006.jpg

Share this post


Link to post
Share on other sites
19 minutes ago, microcipcip said:

My setup is a little bit confusing, in the "Field List & Values" of ProcessWire popup, I see the following (only "title" field!):

Looks like you are viewing this on the backend - you need to view that panel/section when viewing the page on the front-end of the site.

 

19 minutes ago, microcipcip said:

If I try to output da($p->banners->toArray()); I get this list, without the array:

Remember that I said getArray(), not toArray()

  • Like 1

Share this post


Link to post
Share on other sites

All right, I am starting to understand. The reason I only see the "title" field is that I am getting the page by ID, so that tab is showing the page I'm in. Sorry about the mistake of toArray instead of getArray, I didn't notice it!

Is it possible to get a nicely formatted array like the one on "Field List & Values" in ProcessWire popup, if I am in another page?
I am basically building a REST Api so I can't access the templates directly (it's a single page app that I access from http://mysite/api/pages/pageID, I am following this tutorial).

I am using $p = $pages->get($pageId); and then with da($p->banners->getArray()); I basically see the third screenshot I've shared above.

Share this post


Link to post
Share on other sites

Glad it's making sense for you now.

Interestingly I have been thinking about having Tracy use the page that is being edited (when editing a page in the admin), rather than the page for the edit process, but not sure if it is really a good idea because it would prevent investigating the actual edit process page if you did want to. Typically in the backend when using d() or bd() in the console panel I do what you did and define $p to the page I am editing, but of course this doesn't help for the info displayed in the PW Info panel.

I have made a quick modification to the PW Info panel to support my idea of reporting on the page being edited. I have attached the replacement file for the moment. I'd like to hear how you find it. I'll think on it a little more before incorporating in the released version of Tracy.

ProcesswireInfoPanel.inc

 

Share this post


Link to post
Share on other sites

Thanks a lot, this helps a lot as I can now see the fields from the Admin. Is there a reason why debugAll won't show those nicely formatted fields when I debug from the frontend, but the ProcessWire popup will?

  • Like 1

Share this post


Link to post
Share on other sites

Are you talking about the Tracy debugAll() method? When you say it won't show those fields, do you mean the various properties of the images? The output in the PW Info panel is "manually" generated to include all those things. I haven't come across a built in PW method that outputs everything cleanly like that. Take a look at the code I used to generate that array:

https://github.com/adrianbj/TracyDebugger/blob/ac3ff2f6cdfcb151d53f7938d3f4ec270f23b115/ProcesswireInfoPanel.inc#L313-L367

  • Like 2

Share this post


Link to post
Share on other sites
1 minute ago, adrian said:

The output in the PW Info panel is "manually" generated to include all those things.

All right now I understand :lol:. Thanks a lot for your help!

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Peter Knight
      Is there a way to make JPGs progressive by default via the API?
      I've added the following to my site/config.php file but user-uploaded images are often displayed as non progressive.
      $config->imageSizerOptions = array( 'upscaling' => true, // upscale if necessary to reach target size? 'cropping' => true, // crop if necessary to reach target size? 'autoRotation' => true, // automatically correct orientation? 'interlace' => true, // use interlaced JPEGs by default? (recommended) 'sharpening' => 'soft', // sharpening: none | soft | medium | strong 'quality' => 95, // quality: 1-100 where higher is better but bigger 'hidpiQuality' => 60, // Same as above quality setting, but specific to hidpi images 'defaultGamma' => 0.5, // defaultGamma: 0.5 to 4.0 or -1 to disable gamma correction (default=2.0) ); Thanks
    • By cosmicsafari
      Hi all,
      Just wondering if someone with a bit more PW knowledge than me could give a run down of what this method actually does and how its achieved.
      I get that it rebuilds image variations but based on what settings?
      If I wanted to rebuild all the websites image variations but at say a reduced image quality can this be set somewhere globally that this method would take into account?
      For some context I have built a fairly simple module to delete all the image variations connected to any FieldtypeImage which is being used on the website, for the most part this works quite well. As I was quite happy with how that turned out I figured I would give the module another option to rebuild the images also. So there would be a 'Remove' and 'Rebuild' button on the modules config page.
      The idea being that I could use this tool to delete all the image variations, update some global settings then regenerate them all but currently it doesn't appear to do that.
      I assume this is either because my codes borked or im misunderstanding something fundamental about how rebuildVariations() works.
    • By Sergio
      Hi everyone,
      Yesterday I began working on a module to create a filesystem abstraction for files and images using the Flysytem library (http://flysystem.thephpleague.com), out of the necessity of having the images copied (and probably linked) on Amazon S3 and other places like Dropbox. There two reasons why I decided to tackle this:
      1 - When I work on the project in my machine, I need a way to automatically sync the images from the server and/or the external storage.
      When an image is added on the server and the database is imported on my local env, PW shows a blank thumbnail of it. The idea for the module if to check if the page image has a width == 0 and if it exists on the server, add it to the local filesystem.
      2 - In the past, I had to move a large website to a different server in a hurry and a lot of images were left behind (it was a mess). So I'm planning for a possible future worst-case scenario of the server exploding 🙂 
      The code I quickly wrote is below (please bear with me that it's pretty raw at the moment). One thing I had to figure it out is why PW fires the Pageimage::size hook wherever a page is loaded in the admin, even though the thumbnails are already created. I was planning to save the image variations on S3 as well. Can someone clarify?
      I know that @LostKobrakai was working on a similar project, and so I would like to ask him and everyone else if you think I (and who may help) should evolve this idea into a full-featured module where the user can select which server (adapter) to use (AWS, Digital Ocean spaces, Dropbox etc.)
      <?php namespace ProcessWire; use Aws\S3\S3Client; use League\Flysystem\AwsS3v3\AwsS3Adapter; use League\Flysystem\Filesystem; use League\Flysystem\Adapter\Local; use Spatie\Dropbox\Client; use Spatie\FlysystemDropbox\DropboxAdapter; class ProcessFly extends WireData implements Module, ConfigurableModule { public static function getModuleInfo() { return array( 'title' => 'ProcessWire Flysystem Integration', 'version' => 001, 'summary' => 'Synchronize all the page assets uploaded through PW to a specified bucket in Amazon S3 and...', 'author' => 'Sérgio Jardim', 'singular' => true, 'autoload' => true, 'icon' => 'image' ); } public function init() { $this->client = S3Client::factory([ 'credentials' => [ 'key' => '', 'secret' => '', ], 'region' => 'sa-east-1', 'version' => 'latest', ]); $this->bucket_name = ""; $this->dir_name = "images"; $this->s3_adapter = new AwsS3Adapter($this->client, $this->bucket_name, $this->dir_name); $this->s3_filesystem = new Filesystem($this->s3_adapter); // DROPBOX $this->authorizationToken = ""; $this->dropbox_client = new Client($this->authorizationToken); $this->adapter_dropbox = new DropboxAdapter($this->dropbox_client); $this->dropbox_filesystem = new Filesystem($this->adapter_dropbox); $this->addHookAfter('Pages::saved', $this, 'checkImageS3'); // Download images that are not in local filesystem for whatever reason but are available in the remove one. $this->addHookAfter('InputfieldFile::fileAdded', $this, 'uploadImageS3'); // Fired when a file/image is added to a page in the admin // $this->addHookAfter('Pageimage::size', $this, 'uploadImageS3'); // Fired when a file is resized via API. Note: this hook is also called when the page is loaded in Admin. Need to know why. $this->addHookAfter('Pageimage::url', $this, 'redirectImageURL'); //Replace image URL for the S3 path } public function redirectImageURL($event){ if($event->page->template == 'admin') return; else $event->return = "https://s3-sa-east-1.amazonaws.com/[bucket name]/images/" . $event->object->page . "/" . $event->object->name; } // UPLOAD public function uploadImageS3($event){ if(count($event->return)) { //if it is a image resize event get image variation data $file = $event->return; } else { $file = $event->arguments(0); } $filename = $file->name; $filename_original = $file->url; $pathToFile = $file->page . "/" . $filename; $system_path = $file->filename(); try{ $file_on_s3 = $this->s3_filesystem->has($pathToFile); //check if file exists on AWS if(!$file_on_s3) { $contents = file_get_contents($system_path); $this->s3_filesystem->put($pathToFile, $contents, array( 'visibility' => 'public', )); //upload file with the same folder structure as in assets/files: page_id/file_name //Also add a copy to Dropbox (OPTIONAL) $this->dropbox_filesystem->put($pathToFile, $contents); } } catch (Exception $e){ throw new WireException("Error: Image not Added to S3: {$e->getMessage()}"); } } public function checkImageS3($event){ $page = $event->arguments(0); if(count($page->images)) { foreach($page->images as $file) { if($file->width == 0) { return $this->downloadImageS3($page, $file); }; } } } public function downloadImageS3($page, $file){ $pathToFile = $page->id . "/" . $file->name; $file_on_s3 = $this->s3_filesystem->has($pathToFile); //check if file exists on AWS if($file_on_s3) { $image = "https://s3-sa-east-1.amazonaws.com/[bucket name]/images/" . $pathToFile; // $page->images->remove($image); $page->images->add($image); $page->save(); } else { throw new WireException("Error: Image not found on S3: {$file->name}"); } } }  
    • By humanafterall
      Hi,
      I'm using the on the fly image resizing in Processwire to create suitable image sizes for different viewports (using Foundation's Image Interchange).
      All seemed to be working fine but I'm having real trouble with the quality of the outputted image.
      This is the orginal image:

      This is an example of a resized image:

      It looks like it's losing colour information in the process of being resized.
      I've tried setting the default quality to 100% (in the wire/core/ImageSizer.php) but to no avail.
      Could anyone share any light on what might be happening here?
    • By rushy
      Hi 
      My first use of repeaters. They seem very useful, but I'm having a strange problem with the descriptions of the images field. I can't change them after deploying from my local dev server to the live server. I have defined a repeater with one images field and one textarea (multi language) field. This works as expected when added to a template and on the page I add an image and text in 3 languages. I usually populate the image description fields with a caption text in 3 languages so that I can output a caption if required under the image.  Now this all works a treat on my test localhost server, but when deployed to the live site the captions cannot be changed on these repeater image fields. If I login to the live site and change the image text in there - as soon as I hit save the text goes back to what it was before! I am logged in as superuser so can't work out what the problem is. 
      I had a search through the forums but couldn't find a similar problem. Any ideas where to look for some clues to what the problem may be?
      I'm using ProcessWire 3.0.96 
      Many thanks - Paul