Page 1 of 2

Feature Request / How to?

Posted: 31 Jan 2017, 12:26
by sonnenlanze
Hello :)

Me again! Another question. I've seen that uploaded images are always copied in full size to the phocadownloadpap folder.
For space saving reasons I would like to auto-resize the preview-images to a max of 800px (longer side, keep aspect ratio). If the image is alreads smaller it can stay as it is.
There are some code examples to be found with google (http://www.w3bees.com/2013/03/resize-im ... g-php.html) but I'm a complete noob at changing joomla components (and the changes would not survive an update, would they?). How can I achieve something like this? Other files like pdf, word or excel shouldn't be bothered, only jpg (and maybe png).

Thanks alot for any help!
Kind regards,
Vanessa

Re: Feature Request / How to?

Posted: 03 Feb 2017, 01:20
by Jan
Hi, there are many different features of this - the image can be resized before download (happens on user's browser - with help of Java or Javascript) or then on server (like used in Phoca Gallery or Phoca Cart - but in such case original images are stored on server to be ready for making thumbnails again)

Jan

Re: Feature Request / How to?

Posted: 03 Feb 2017, 10:42
by sonnenlanze
Hi Jan :)

Thank you for your reply!

I don't mind which alternative - as long as the "final result" is to have large original images (as you have in the phocadownload folder) and configurable size thumbnails in the phocadownloadpap folder. That would be just perfect :)
At the moment, if I upload an image through the frontend, two full-size copies (3-8 MB) are stored :( That's just redundant.

And if I upload an image through the backend, I would need to resize the image myself before uploading it, because you have two separate links in the backend. Wouldn't it be much besser, if people only had to link/upload one and the thumbnails would be made automatically?

I know and use Phocagallery and I don't mind if you would use the same code twice. Having the frontend upload make the thumbnail automatically would be vital as they cannot start the "make thumbnail" routine.

Kind regards,
Vanessa

Re: Feature Request / How to?

Posted: 03 Feb 2017, 10:48
by sonnenlanze
BTW: Can you hint to me which Javascript file it is that does the upload from the frontend? Maybe I wil be able to add a resize function myself (by trial and error *g*)

Re: Feature Request / How to?

Posted: 05 Feb 2017, 18:20
by Jan
Hi, if you look at Phoca Gallery or Phoca Cart, there the "plupload" is used for multiple uploading the images (and they should be able to change the size of the image :idea: )

Jan

Re: Feature Request / How to?

Posted: 05 Feb 2017, 19:01
by sonnenlanze
Yes, but in the Fronten you don't have multi upload

Re: Feature Request / How to?

Posted: 05 Feb 2017, 20:01
by Jan
Yes, unfortunately, it is not in Phoca Download, so it needs to be added to the Phoca Download (customized). For now this is the only one way. As Phoca Download is a download manager component, it is not assumed, that files you upload, will be somehow changed (so as default there is no rizes function for images) And for now, unfortunately, because of time, I still didn't implement the multiple upload feature to frontend of Phoca Download :-( :-(

Jan

Re: Feature Request / How to?

Posted: 05 Feb 2017, 22:53
by sonnenlanze
No problem. But which file would I need to customize to implement a resize? I'm sure I'll find out sooner or later but if you can tell me at which file(s) to look, I can try to customize it myself :)
Thanks a lot!

Re: Feature Request / How to?

Posted: 06 Feb 2017, 18:43
by sonnenlanze
I THINK I've found the file where I would need to change something:

com_phocadownload\libraries\phocadownload\file\fileupload.php
Line 617/618

Code: Select all

// Image check
		$imginfo	= null;
		$images		= explode( ',', $paramsL['image_extensions']);
		
		if(in_array($format, $images)) { // if its an image run it through getimagesize
			
			$group = PhocaDownloadSettings::getManagerGroup($manager);
			if($group['i'] == 1) {
				if ($chunkEnabled != 1) {
					if(($imginfo = getimagesize($file['tmp_name'])) === FALSE) {
						$err = 'COM_PHOCADOWNLOAD_WARNINVALIDIMG';
						$err = $imginfo[0];
						return false;
					} //==> ADD RESIZE FUNCTIONALITY HERE 
				} 
			}
		} else if(!in_array($format, $images)) { // if its not an image...and we're not ignoring it
			$allowed_mime = explode(',', $paramsL['upload_mime']);
			$illegal_mime = explode(',', $paramsL['upload_mime_illegal']);
			if(function_exists('finfo_open')) {// We have fileinfo
				$finfo	= finfo_open(FILEINFO_MIME);
				$type	= finfo_file($finfo, $file['tmp_name']);
				if(strlen($type) && !in_array($type, $allowed_mime) && in_array($type, $illegal_mime)) {
					$err = 'COM_PHOCADOWNLOAD_WARNINVALIDMIME';
					return false;
				}
				finfo_close($finfo);
			} else if(function_exists('mime_content_type')) { // we have mime magic
				$type = mime_content_type($file['tmp_name']);
				if(strlen($type) && !in_array($type, $allowed_mime) && in_array($type, $illegal_mime)) {
					$err = 'COM_PHOCADOWNLOAD_WARNINVALIDMIME';
					return false;
				}
			}
		}
Is that the right spot to try?

Re: Feature Request / How to?

Posted: 07 Feb 2017, 16:25
by sonnenlanze
Hmm... I tried to implement it there but it didn't do anything... I'm not sure if that's the right spot to add changes. If I use Frontend Upload, there's a Ajax/Loading-Ring showing, so I assume the upload happens via js and not native php. Also, I am not able to find the spot where you copy the uploaded file to the phocadownloadpap-folder. That would be the right spot to add a resize function for images (depending on the extension of the file)...