Jump to content

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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

You guys are pretty fast... :-)

Ok, I'll dig deeper when I'm more familiar with all this great stuff. Too much to learn...

Regards, Thomas

Share this post


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

Share this post


Link to post
Share on other sites

@Soma: Boah! works great and on a 'per field basis'! absolute great! ^-^

Share this post


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

Share this post


Link to post
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? :)

Share this post


Link to post
Share on other sites

Soma! Soma! Soma!

^ That's how many of him there are.

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 arnd
      Hi,
      I have a repeater with some images in it.
      As Superuser I can work with the Actions (rotate...). But my Users with lower Rights can't use this Actions.
      The same User can use the Actions on images outsite a Repeter-Field. So I think it's not a Problem of Rights-Management but from Images in Repeater Fields.
      ProcessWire 3.0.164.  Bug? Or can I manage this in the settings?
      Thanks in advance
    • By Mats
      BETA: SplashAndGrab
      https://github.com/madebymats/InputfieldSplashAndGrab
      This module attaches a search input to selected image fields that lets you search and download images from Unsplash.
      (Unsplash is a stock photo service where you can download images for free and use as you wish. No strings attached.)   
      You can search by string, colors, orientation/crop and order by relevance or time published
      I find Unsplash useful both for placeholder images when building sites but also as a time saver for editors if they don’t have any images at hand, just search, download and publish.

      Thanks to @apeisa for building the  FlickrInputField Module and @Robin S for AddImageUrls,  took a lot ideas and code from those modules.
    • By markus_blue_tomato
      We have created a module to create BlurHash strings for images while uploading in ProcessWire. This blurry images will be saved in the database because they are very small (20-30 characters) and can be used for Data-URL's  as placeholders for image-lazy loading.
      https://github.com/blue-tomato/ImageBlurhash
      E.g. where we use this in production:
      https://www.blue-tomato.com/en-INT/blue-world/ https://www.blue-tomato.com/en-INT/blue-world/products/girls-are-awesome/ https://www.blue-tomato.com/en-INT/buyers-guides/skateboard/skateboard-decks/ https://www.blue-tomato.com/en-INT/team/anna-gasser/
    • By EyeDentify
      Hello dear PW gurus.

      I have stumbled over a strange error that i all of sudden got when trying to upload an image to a images field on a page.
      There where images allready stored in the field that i wanted to keep, but during the upload the error apear and after that all images are gone from the field and i can´t upload any, i just get the error every time.
      I am running ProcessWire 3.0.153 dev.
      Update:
      After looking in the assets folder i find the folder for the page and the image files seems to be there including the ones i tried to upload when the error occured.
      But they don´t show up in the images field in the page editor.
       
      The error reported:
       
      SQLSTATE[01000]: Warning: 1265 Data truncated for column 'ratio' at row 1 And here is a screenshot of the event:

      The TracyDebugger Error reporting:

      I hope you fine folks could point me in a direction.
      But it seems our old pal set_time_limit() is back.

      Regards, EyeDentify
    • By rushy
      Hi all
      Continuing my first project where I am creating and manipulating stuff from the frontend. Till now I've always added things like images from the backend, but in this project I need to add and move images from a frontend control. This is a photo album where images are stored in albums, each album being a page containing a Pageimages array in the usual way. So what I want to know is how do I move an image from one album (page) to another in the frontend? I just need some guidance on how to approach this.  I suppose I need to do a copy and delete - but how do I copy an image or images from one page to another? What function should I use to create a new image on an existing page? I include a code snippet from the server side of my delete image request and it works fine. I'd like to implement something similar for a move and upload new image request. 
      Many thanks for any help. Paul 
      <?php namespace ProcessWire; // sanitize inputs as 1-line text $action = $sanitizer->text($input->post('action')); $instr = $sanitizer->text($input->post('input')); $sel = $input->post('selected'); // Expect JSON for image selected image list $selected = json_decode($sel); $nosel = count($selected); $response = array(); // for building JSON response switch($action) { // delete selected images case 'delete': $out = "<p>Deleted $nosel image(s)</p>"; foreach($selected as $item){ $album = $pages->get($item->album); $album->of(false); $out .= "<p>Image {$item->file} from album {$album->title}</p>"; $album->images->delete($item->file); $album->of(true); } $out .= saveUpdatedAlbums($pages, $selected); // add the response message for the delete $response['message'] = $out; break; ...... // save any album that had an image deleted function saveUpdatedAlbums($pages, $selected) { $cur = ''; $out = ''; foreach($selected as $item){ $album = $pages->get($item->album); if($album->id != $cur) { $album->of(false); $album->save('images'); $album->of(true); $cur = $album->id; $out .= "<p>Updated album {$pages->get($cur)->title}</p>"; } } return $out; }  
       
       
×
×
  • Create New...