Jump to content

How to create image variations?


Jay D
 Share

Recommended Posts

Hi all, 

 

I am new to PW, and so far I am really digging it. Longtime WP and Laravel user, so PW seems very clean and efficient.

 

One issue I am having a hard time discovering is; When I create an image array, I want to create permanent thumbnails that, are not created at time of page load. I see I have a *0x250.jpg file, but not sure where I can change the settings to make a 250x200 type image. 

 

Thank you in advance, I have been searching, and it seems most forums point to temp resizing.

 

Jay

Link to comment
Share on other sites

1 hour ago, Jay D said:

I am new to PW, and so far I am really digging it.

Welcome to the forums and ProcessWire ?.

1 hour ago, Jay D said:

I want to create permanent thumbnails that, are not created at time of page load.

ProcessWire does this only once. So, the next time, it will just load the thumbnail you requested, hence it is permanent unless you delete it. 

1 hour ago, Jay D said:

I see I have a *0x250.jpg file,

I think you mean 0x260. That is generated automatically by ProcessWire for backend use. You can create your own (other sizes) like shown below. This code goes into your template file.

// Example of outputting a thumbnail gallery of Pageimage objects
foreach($page->images as $image) {
  // $image and $thumb are both Pageimage objects
  $thumb = $image->size(250, 200);// width x height
  echo "<a href='$image->url'>";
  echo "<img src='$thumb->url' alt='$image->description' />";
  echo "</a>";
}

You can use the above code to create the thumbnails outside a page load if you wish. Have a look at the docs here: https://processwire.com/api/ref/pageimage/

 

Edited by kongondo
  • Like 2
Link to comment
Share on other sites

On 3/8/2019 at 6:42 PM, kongondo said:

I think you mean 0x260. That is generated automatically by ProcessWire for backend use. You can create your own (other sizes) like shown below. This code goes into your template file.


// Example of outputting a thumbnail gallery of Pageimage objects
foreach($page->images as $image) {
  // $image and $thumb are both Pageimage objects
  $thumb = $image->size(250, 200);// width x height
  echo "<a href='$image->url'>";
  echo "<img src='$thumb->url' alt='$image->description' />";
  echo "</a>";
}

You can use the above code to create the thumbnails outside a page load if you wish. Have a look at the docs here: https://processwire.com/api/ref/pageimage/

This is exactly what I am trying to do.
Create image variations outside a page load, so not inside the template file but during the initial upload process in the backed/admin panel when then thumbnail is generated.

Had a look at the docs you like for the Pageimage class but I am not sure how to use that info.
Reading through this https://selftaughtcoders.com/from-idea-to-launch/lesson-14/how-to-use-classes-in-php/ and then for example inserting

<?php

$galleryImg = new Pageimage;

$defaultOptions = array(
	'upscaling' => false,
	'cropping'  => false,
	'quality'   => 90,
);

$galleryImg->size(1280, 0, $defaultOptions);

into _func.php of the Intermediate profile does not create the desired 1200px width image variation.
Would be super grateful to learn how I can generate image variations during the initial upload process in the admin panel.
Thank you.

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...