问题
Is there any property in ckeditor that will resize the image after uploading to a specified dimension. for eg: if user uploads a image of 1000*1000 px
and doesn't resize it, it can be a massacre. As i am saving and displaying on the same page without refresh using ajax.
All i want is to automatically resize image on upload from ckeditor.
As well, is there any way that i can find using jquery whether there is any image in the text saved by user, as a user may or may not upload a image, I am using inplace ckeditor.
回答1:
CKFinder is an excellent companion to CKEditor, and allows one to set the maximum size of an uploaded image in its configuration.
If you don't want to use that, you resize the image yourself in PHP with something like this:
<?php
$maxWidth = 250;
$maxHeight = 500;
$size = getimagesize($url);
if ($size) {
$imageWidth = $size[0];
$imageHeight = $size[1];
$wRatio = $imageWidth / $maxWidth;
$hRatio = $imageHeight / $maxHeight;
$maxRatio = max($wRatio, $hRatio);
if ($maxRatio > 1) {
$outputWidth = $imageWidth / $maxRatio;
$outputHeight = $imageHeight / $maxRatio;
} else {
$outputWidth = $imageWidth;
$outputHeight = $imageHeight;
}
}
?>
From: Arbitrary image resizing in PHP
来源:https://stackoverflow.com/questions/6339664/ckeditor-property-to-resize-a-image