Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Before you read the answer, please rethink this issue. Do you have a reason why you would want to resize on upload?<br> I actually want my sites to store the full images, and display a resized copy of the image.<br> This way, if you later decide to display the images in a bigger size, you just change the resize code, and it will still look good. if you resize on upload, your images are already small, if you now change your website to display bigger ones, you will have to re-upload all images.</p> <hr> <p>$visual is a UploadField, it has no resize capabilities. and no method called <code>resizeByHeight</code>, so the whitescreen is probably because you are calling a method that does not exist, and your error reporting is turned off.</p> <p>resize methods are on the Image class, but they always make a copy of the file, so they do not resize the image itself, but instead save a resized copy of that image in the _resampled folder.</p> <p>there is currently no functionality built in to actually resize the original image. however it should be fairly simple to implement by sub classing <code>UploadField</code> and overwriting either the method <code>upload</code> or one of the methods it uses to save the file.</p> <p>A working example I just built:</p> <pre><code>class MyUploadField extends UploadField { protected function saveTemporaryFile($tmpFile, &amp;$error = null) { $file = parent::saveTemporaryFile($tmpFile, $error); if ($file &amp;&amp; is_a($file, 'Image')) { // only attempt to resize if it's an image $filePath = Director::baseFolder() . "/" . $file-&gt;Filename; // create a backend (either GDBackend or ImagickBackend depending on your settings) $backend = Injector::inst()-&gt;createWithArgs(Image::get_backend(), array($filePath)); if ($backend-&gt;hasImageResource() &amp;&amp; $backend-&gt;getHeight() &gt; 100) { // if it is a working image and is higher than 100px, resize it to 100px height $newBackend = $backend-&gt;resizeByHeight(100); if ($newBackend) { // resize successful, overwrite the existing file $newBackend-&gt;writeTo($filePath); } } } return $file; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload