public function uploadImage($id, $logo) {
$uploadedImage = $logo;
if (!$logo->isImage()) {
throw new XenForo_Exception(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true);
}
$dimensions = array(
'width' => $uploadedImage->getImageInfoField('width'),
'height' => $uploadedImage->getImageInfoField('height'),
);
$imageType = $logo->getImageInfoField('type');
if (!in_array($imageType, array(IMAGETYPE_GIF, IMAGETYPE_PNG, IMAGETYPE_JPEG))) {
throw new XenForo_Exception(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true);
}
$imageInfo = getimagesize($logo->getTempFile());
if (!$imageInfo) {
throw new XenForo_Exception('Non-image passed in to applyAvatar');
}
$width = $imageInfo[0];
$height = $imageInfo[1];
$imageType = $imageInfo[2];
if (!in_array($imageType, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
throw new XenForo_Exception('Invalid image type passed in to applyAvatar');
}
if (!XenForo_Image_Abstract::canResize($width, $height)) {
throw new XenForo_Exception(new XenForo_Phrase('uploaded_image_is_too_big'), true);
}
$target = XenForo_Helper_File::getExternalDataPath().'/profil/'.$id.'.jpg';
$image = XenForo_Image_Abstract::createFromFile($logo->getTempFile(), $logo->getImageInfoField('type'));
$image->output(IMAGETYPE_JPEG, $target); //save
return true;
}