Jump to content

Fixed image size


Eltom
 Share

Recommended Posts

Hi all,

I'm fairly new to Processwire. As far as I can see, it's a great tool to get my work done! :-)

There's just one question right now: Is there a way to define a fixed width and/or height for an image in the backend? I'm aware of the "maximum width/height" options, but I need a fixed width in my case. Images larger than the defined width should automatically downsize, images smaller should be rejected with an error.

Regards,

Thomas

Link to comment
Share on other sites

There's just one question right now: Is there a way to define a fixed width and/or height for an image in the backend? I'm aware of the "maximum width/height" options, but I need a fixed width in my case. Images larger than the defined width should automatically downsize, images smaller should be rejected with an error.

Hi Thomas, welcome.

Sorry, I'm a bit short with time.

Assuming with 'should be rejected' you mean on upload of images, I think [best way | one way] [w|c]ould be to write a simple and small module that must hook somewhere into Uploadprocess of images and check with PHP's getimagesize() the dimensions. And if not suite the minimums, delete the file and throw a message to the user.

Unfortunately I actually don't know which Hook would be the best for that. So, if you are not familiar with PW-modules (as of you are new to PW), you may wait until one of the forum pro's come along here, - or later todays afternoon I can spent some time on looking to that, because I will need an upload module for myself in the near future.

Link to comment
Share on other sites

@Eltom: you're essentially describing a new minimum size setting here, which as far as I know doesn't yet exist but would admittedly be quite nice at times.

So yes, @horst is right in that you'd currently have to create a new module to implement this. You could also submit this as a feature request to Wishlist & Roadmap section here on the forum.. though posting here may already be enough to catch Ryan's attention :)

Taking a look at the source of InputfieldImage.module, there's a ___fileAdded() method (three underscores means that it's hookable) that could be used by a module. This method actually handles resizing image if it's larger than given max size, so something like this should work:

  • hooking before InputfieldImage::fileAdded,
  • checking if image size is smaller than minimum size given (settings of this new module or perhaps within field settings, though I'm not sure if there's a proper place to hook and add something like that there by hooking after InputfieldImage::getConfigInputFields and adding new field to returned InputfieldWrapper object.. or it could simply be a hard-coded value)
  • .. and if it is, removing file and outputting error (like @horst already described above.)

Sounds relatively simple to do, really. If you're even remotely interested in PW module development, you could give it a try yourself.. and please don't hesitate to ask if you face any problems!

Extra tip: HelloWorld.module is great starting point for a module that adds hooks :)

Edited by teppo
  • Like 1
Link to comment
Share on other sites

Good idea I also have need for it, and fun to make module so there you go (not exactly easy):

A first version of ImageMinSize

Adds a min dimension setting  (under Input tab) to image fields.

If requirements doesn't meet it throws error and deletes images.

To have it meet exact dimension, you can simply set min and max dimensions to same values.


Edit: The module has now its home http://processwire.com/talk/topic/4091-imageminsize/

  • Like 11
Link to comment
Share on other sites

Soma, the "Hero" member! :-)

Fantastic, thank you!

More and more I like what I see, but please forgive me: It will take some time since I am able to contribute...  :undecided:

Regards, Thomas

Link to comment
Share on other sites

Good idea I also have need for it, and fun to make module so there you go (not exactly easy):

Nice job Soma! Any chance I can talk you into adding this to the modules directory? :)

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...