- Getting Started
- Browser Support
- Languages Support
- Shortcuts
- Activation
- Examples
- Customize the Editor
- Use-cases
- Plugins
- APIs
- Development Frameworks
- Server Integrations
- Server SDKs
- Migration Guides
- Changelog
- Tutorials
PHP Image Resize
How it works
- Upload image to the server.
- Image is resized when it is stored on the server.
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);
}
?>
Additional Resources
- Building a Support System Using Laravel PHP Framework and Froala HTML Editor Software – Part 1
- Building a Support System Using Laravel PHP Framework and Froala HTML Editor Software – Part 2
- Building a Support System Using Laravel PHP Framework and Froala HTML Editor Software – Part 3
- How To Use WYSIWYG Editor In PHP
Do you think we can improve this article? Let us know.