Jump to content

How to resize filesystem image without making use of phpThumb or timThumb?


titanium
 Share

Recommended Posts

Hi,

I wonder if there is an easy way to resize an image in the filesystem? Reason is: I need to display the same image in different sizes in some templates, but the image is already in the filesystem (in fact, it is deployed by another system). Since it should work automatically, I don't want to use the backend and create a field for it by hand.

For example: instead of doing something like this (every picture has to be sized with Photoshop beforehand):

<img src="/mypath/myimage.png" width="250" alt=""/>
<img src="/mypath/myimage.png" width="500" alt=""/>

it would be convenient to do something like this (does NOT work, just for illustrating what I would like to achieve):

<?php $image = new PageImage('/var/www/mypath/myimage.png'); ?>
<img src="<?php echo $image->size(250,0)->url; ?>" width="250" alt=""/>
<img src="<?php echo $image->size(500,0)->url; ?>" width="500" alt=""/>

In this manner the system would do the resizing, and Photoshop could rest in peace.

I know phpThumb or timThumb can do this similar as well, but I would like to do it the Processwire way.

Any hints welcome :-)

Link to comment
Share on other sites

Well, the easiest solution would probably still be to assign an images field to your template(s) and import the image from the other system.

Then and the images are stored in /site/assets/ - which is the Pw way :)

If you can't do it this way, check out the ImageSizer class in /wire/core/.

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

×
×
  • Create New...