Days
Hours
Minutes
Seconds
x

Froala Editor v4.3 is hereLEARN MORE

Skip to content

PHP Image Resize

How it works

  1. Upload image to the server.
  2. Image is resized when it is stored on the server.

Jump to Complete Example

Image Upload

The Server Upload section describes the steps to upload an image to a server. Resizing images on the editor only changes the size displayed in the browser. Changing the physical size of an image occurs on the server side.

Resize Image

The editor's PHP SDK uses the PHP Imagick::resizeImage method to resize images before storing them on disk. You can use all the options available for it.

$options = array(
  'resize' => array(
    // Width.
    'columns' => 300,

    // Height.
    'rows' => 300,

    // Keep aspect ratio.
    'bestfit' => true
  )
);

$response = FroalaEditor_Image::upload('/uploads/', $options);

Complete Example

<script>
  new FroalaEditor('.selector', {
    // Set the image upload URL.
    imageUploadURL: '/image_upload.php',

    imageUploadParams: {
      id: 'my_editor'
    }
  })
</script>
<?php

// Include the editor SDK.
require 'PATH_TO_FROALA_SDK/lib/froala_editor.php';

$options = array(
  'resize' => array(
    // Width.
    'columns' => 300,

    // Height.
    'rows' => 300,

    // Keep aspect ratio.
    'bestfit' => true
  )
);

// Store the image.
try {
  $response = FroalaEditor_Image::upload('/uploads/', $options);
  echo stripslashes(json_encode($response));
}
catch (Exception $e) {
  http_response_code(404);
}

?>

Do you think we can improve this article? Let us know.