In RSComments there's the possibility to upload a file with a comment, that's showed as a link. By changing line 1129 from components/com_rscomments/helpers/rscomments.php from
$with[] = '<a href="'.RSCommentsHelper::route('index.php?option=com_rscomments&task=download&cid='.$comment->IdComment,false).'" title="'.JText::_('RSC_ATTACHMENT').':: " class="hasTip"><img src="'.RSCommentsHelper::ImagePath('attachment.png').'" alt="'.JText::_('RSC_ATTACHMENT').'" />'.$comment->file.'</a>';
to
$with[] = '<a href="'.RSCommentsHelper::route('index.php?option=com_rscomments&task=download&cid='.$comment->IdComment,false).'" ><img src="'.RSCommentsHelper::route('index.php?option=com_rscomments&task=download&cid='.$comment->IdComment,false).'" /></a>';
and by only allowing .jpg's to be uploaded, images are showed in the comment. So far, so good. The second step I've tried is to resize the image when it's over a certain pixelsize. And this doesn't work. As far as I understand because imagecreatefromjpeg is not working. As php newbie I can't figure out why. Is there anyone here that can point me in the right direction?
The upload is handled by components/com_rscomments/controller.php. This ia a part of function uploadfile():
while (JFile::exists($uploadFolder.$filename.'.'. $ext))
$filename .= rand(10, 99);
$dest = $uploadFolder.$filename.'.'.$ext;
JFile::upload($src, $dest);
I've changed it to:
while (JFile::exists($uploadFolder.$filename.'.'. $ext))
$filename .= rand(10, 99);
// end original function and start added resizing part
// Get current sizes
list ($startWidth,$startHeight) = getimagesize($src);
// conditional statement
if ($startWidth > 500) {
// Load image
$src_to_resize = imagecreatefromjpeg($src);
// setting new width and calculate new height
$newWidth = 500;
$newHeight = (int) ($startHeight * (500 / $startWidth));
// create a new temporary image
$tmp = imagecreatetruecolor($newWidth, $newHeight);
// Resize
imagecopyresized($tmp, $src_to_resize, 0, 0, 0, 0, $newWidth, $newHeight, $startWidth, $startHeight);
// Output
imagejpeg($tmp,$src_to_resize,70);
JFile::upload($src_to_resize, $dest);
// echo's to see what's going on
$msg = '\n$startWidth = '.$startWidth;
$msg .= '\n$startHeight = '.$startHeight;
$msg .= '\n$newWidth = '.$newWidth;
$msg .= '\n$newHeight = '.$newHeight;
$msg .= '\n$src inside added code = '.$src;
$msg .= '\n$src_to_resize inside added code = '.$src_to_resize;
$msg .= '\n$tmp inside added code = '.$tmp;
$msg .= '\n$dest inside added code = '.$dest;
} else {
JFile::upload($src, $dest);
}
The result of the $msg:
$startWidth = 600
$startHeight = 183
$newWidth = 500
$newHeight = 152
$src inside added code = /tmp/phpSj2WFm
$src_to_resize inside added code = Resource id #126
$tmp inside added code = Resource id #127
$dest inside added code = serverpath/test600px.jpg