public function actionCropElementAction()
{
$this->requireAjaxRequest();
$assetId = craft()->request->getRequiredPost('assetId');
$asset = craft()->assets->getFileById($assetId);
$constraint = 500;
if ($asset) {
// Never scale up the images, so make the scaling factor always <= 1
$factor = min($constraint / $asset->width, $constraint / $asset->height, 1);
$imageUrl = $asset->url . '?' . uniqid();
$width = round($asset->width * $factor);
$height = round($asset->height * $factor);
$fileName = $asset->title;
$html = '<img src="' . $imageUrl . '" width="' . $width . '" height="' . $height . '" data-factor="' . $factor . '" data-constraint="' . $constraint . '"/>';
$this->returnJson(array('html' => $html));
}
}