Attached Images Resizer, Converter & File Size Reducer

Looking for an Extension? Have an Extension request? Post your request here for help. (Note: This forum is community supported; while there is an Extensions Development Team, said team does not dedicate itself to handling requests in this forum)
Get Involved
User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 16719
Joined: Thu Jan 06, 2005 1:30 pm
Location: Fishkill, NY
Name: David Colón
Contact:

Re: Attached Images Resizer, Converter & File Size Reducer

Post by DavidIQ » Tue Feb 10, 2015 9:56 pm

Volksdevil wrote:So the building blocks are there but yet nobody has taken it on as a standalone extension for posts.
It's integrated into plupload, which is used for uploading any and all attachments in 3.1.
Apply to become a Jr. Extension Validator
My extensions | In need of phpBB services? | Was I helpful today?
No unsolicited PMs unless you're planning on asking for paid help.

User avatar
Volksdevil
Registered User
Posts: 2414
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Re: Attached Images Resizer, Converter & File Size Reducer

Post by Volksdevil » Tue Feb 10, 2015 11:35 pm

As I thought...So that makes things easier for somebody to make use of it hopefully.
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60

User avatar
phpnewbtard
Registered User
Posts: 83
Joined: Mon Jan 26, 2015 2:22 pm
Contact:

Re: Attached Images Resizer, Converter & File Size Reducer

Post by phpnewbtard » Wed Feb 11, 2015 1:44 pm

deleted
Last edited by phpnewbtard on Wed Apr 01, 2015 1:24 am, edited 1 time in total.

User avatar
Volksdevil
Registered User
Posts: 2414
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Re: Attached Images Resizer, Converter & File Size Reducer

Post by Volksdevil » Wed Feb 11, 2015 8:26 pm

So that ^^ edit can be used on 3.1.3?
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60

User avatar
phpnewbtard
Registered User
Posts: 83
Joined: Mon Jan 26, 2015 2:22 pm
Contact:

Re: Attached Images Resizer, Converter & File Size Reducer

Post by phpnewbtard » Thu Feb 12, 2015 7:50 pm

deleted
Last edited by phpnewbtard on Wed Apr 01, 2015 1:25 am, edited 1 time in total.

User avatar
Volksdevil
Registered User
Posts: 2414
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Re: Attached Images Resizer, Converter & File Size Reducer

Post by Volksdevil » Fri Feb 13, 2015 1:46 am

Wow, how did I not know about this before?! :shock:
I just noticed that if I view all the posted attachments from ACP, then refresh, the size just keeps going down!
Gone from 50MB to 15MB!

Edit: Still something weird though, just view a topic, and it's jumped back up to 25MB now. :?

Also, will this work with avatars? Just wondering because I already run some code for that? Wonder if it's interfering?

Could the two be combined? Reducing file size of posted images, and reducing pixel size of avatars?
What I currently have is some code that will resize (In pixels) avatars to the dimensions no bigger than specified in the ACP. To use it this has to be commented out:

Code: Select all

		if (!$this->upload->valid_dimensions($this))
		{
			$this->error[] = $user->lang($this->upload->error_prefix . 'WRONG_SIZE',
				$user->lang('PIXELS', (int) $this->upload->min_width),
				$user->lang('PIXELS', (int) $this->upload->min_height),
				$user->lang('PIXELS', (int) $this->upload->max_width),
				$user->lang('PIXELS', (int) $this->upload->max_height),
				$user->lang('PIXELS', (int) $this->width),
				$user->lang('PIXELS', (int) $this->height));

			return false;
		}

		return true;
	}
And then this placed beneath it:

Code: Select all

if (!$this->upload->valid_dimensions($this))
{
$valid = $this->create_thumb();

if (!$valid)
{
$this->error[] = sprintf($user->lang[$this->upload->error_prefix . 'WRONG_SIZE'], $this->upload->min_width, $this->upload->min_height, $this->upload->max_width, $this->upload->max_height, $this->width, $this->height);

return false;
}
}
return true;
}
function create_thumb()
{
global $config;

if ($this->width > $this->height) 
{
$thumb_width = $this->upload->max_width;
$thumb_height = $this->height*($this->upload->max_height/$this->width);
}
else if ($this->width < $this->height) 
{
$thumb_width = $this->width*($this->upload->max_width/$this->height);
$thumb_height = $this->upload->max_height;
}
else /* $this->width == $this->height */
{
$thumb_width = $this->upload->max_width;
$thumb_height = $this->upload->max_height;
}

if ($config['img_imagick'] && function_exists('passthru'))
{
$quality = '';
$sharpen = '';
$frame = '';
$animation = '';
if ( $this->mimetype == 'image/jpeg' )
{
$quality = '-quality 80'; // 80%
/** Reduction in linear dimensions below which sharpening will be enabled */
if ( ( $thumb_width + $thumb_height ) / ( $this->width + $this->height ) < 0.85 )
{
$sharpen = '-sharpen 0x0.4';
}
}
elseif ($this->mimetype == 'image/png')
{
$quality = '-quality 95'; // zlib 9, adaptive filtering
}
elseif ($this->mimetype == 'image/gif')
{
if($this->width * $this->height > 1.0e6)
{
// Extract initial frame only
$frame = '[0]';
}
else
{
$animation = ' -coalesce ';
}
}
if (substr($config['img_imagick'], -1) !== '/')
{
$config['img_imagick'] .= '/';
}
$cmd = 
escapeshellcmd($config['img_imagick']) . 'convert' . ((defined('PHP_OS') && preg_match('#^win#i', PHP_OS)) ? '.exe' : '') .
" {$quality} -background white -size {$this->width} ".
escapeshellarg($this->destination_file . $frame) .
$animation .
// For the -resize option a "!" is needed to force exact size,
// or ImageMagick may decide your ratio is wrong and slice off
// a pixel.
' -thumbnail ' . escapeshellarg( "{$thumb_width}x{$thumb_height}!" ) .
" -depth 8 $sharpen " .
escapeshellarg($this->destination_file) . ' 2>&1';

@passthru($cmd);

if (($this->image_info = @getimagesize($this->destination_file)) !== false)
{
$this->width = $this->image_info[0]; // the _real_ width
$this->height = $this->image_info[1]; // the _real_ height
if ($this->upload->valid_dimensions($this)) 
{
return true;
}
}
}
if (extension_loaded('gd'))
{
/* This code is greatly based on MediaWiki's thumbnail generation process */
$typemap = array(
'image/gif' => array( 'imagecreatefromgif', 'palette', 'imagegif' ),
'image/jpeg' => array( 'imagecreatefromjpeg', 'truecolor', array( __CLASS__, 'imagejpegwrapper' ) ),
'image/png' => array( 'imagecreatefrompng', 'bits', 'imagepng' ),
'image/vnd.wap.wbmp' => array( 'imagecreatefromwbmp', 'palette', 'imagewbmp' ),
'image/xbm' => array( 'imagecreatefromxbm', 'palette', 'imagexbm' ),
);
if (!isset( $typemap[$this->mimetype] ))
{
return false;
}

list($loader, $color_style, $save_type) = $typemap[$this->mimetype];

if (!function_exists($loader))
{
return false;
}
$src_image = call_user_func( $loader, $this->destination_file );
$thumb = imagecreatetruecolor($thumb_width, $thumb_height);

// Initialise the destination image to transparent instead of
// the default solid black, to support PNG and GIF transparency nicely
$background = imagecolorallocate( $thumb, 0, 0, 0 );
imagecolortransparent( $thumb, $background );
imagealphablending( $thumb, false );

if( $color_style == 'palette' ) {
imagecopyresized( $thumb, $src_image,
0,0,0,0,
$thumb_width, $thumb_height, $this->width, $this->height );
} else {
imagecopyresampled( $thumb, $src_image,
0,0,0,0,
$thumb_width, $thumb_height, $this->width, $this->height );
}
imagesavealpha( $thumb, true );

call_user_func( $save_type, $thumb, $this->destination_file );
imagedestroy($thumb);
imagedestroy($src_image);
$this->width = $thumb_width;
$this->height = $thumb_height;
return true;
}
return false;
}

static function imagejpegwrapper( $dst_image, $thumb_path ) {
imageinterlace( $dst_image );
imagejpeg( $dst_image, $thumb_path, 95 );
}
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60

User avatar
Volksdevil
Registered User
Posts: 2414
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Re: Attached Images Resizer, Converter & File Size Reducer

Post by Volksdevil » Fri Feb 13, 2015 8:57 pm

There's something weird going on with my attachments. It's doing my damn head in!

Any time I view 'Manage attachments' in the ACP, I always have a warning that the stats need resync. My attachment size is now back up to 37mib :? How can it jump up just like that when no new images have been added?!
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60

User avatar
Volksdevil
Registered User
Posts: 2414
Joined: Sun Oct 03, 2010 2:03 pm
Location: Lancashire, UK
Name: Neil
Contact:

Re: Attached Images Resizer, Converter & File Size Reducer

Post by Volksdevil » Tue Feb 24, 2015 10:36 pm

Anyone? :)
My phpBB Extensions
Finally found great Website Hosting from Image KUALO!
Do NOT use 123-reg.co.uk - Incapable of running phpBB!
:ugeek: TekNeil - Streamer on Mixer | My Volkswagen Corrado G60

Movie
Registered User
Posts: 127
Joined: Sun Nov 02, 2014 2:54 pm
Location: Chicago Illinois Area.

Re: Attached Images Resizer, Converter & File Size Reducer

Post by Movie » Wed May 27, 2015 12:38 am

][Moon][Shine][ wrote:This is not about just resizing displayed images as discussed in the ReIMG Image Resizer thread, but an extension that hooks itself to the attachment function and post-processes files if they are images.

The idea is to optimize forum performance by taking care of image type and file size. People tend to upload pics directly from their camera, resulting in megapixel images with several MB in size. Even if the displayed image is downsized to fit the max width of the posting area it is still stored and loaded in full size, eating away storage space on the server, as well as bandwidth and results in longer page load times (important for search engine rating).

So if a forum member uploads a picture as attachment, the file should automatically be resized to a configured value (like 800x600 or 600x800 keeping the aspect ratio) and converted to JPG with a configured JPG quality setting (like 80%) if it's a PNG or GIF (with the exception of animated GIFs; if such distinction is not possible than no GIF conversion, so that animated GIFs are still possible). AFAIK such functionality should easily be possible using ImageMagick, which is available on any webserver.

Such picture treatment has a huge impact. Right now I do that processing on my Vanilla forum manually (which is cumbersome if people upload a lot of pictures), and I can tell that it brings down pictures file sizes from up to 5 MB for regular pics directly coming from a camera to less than 100 KB most of the times.

It would be really great to have such automatic picture attachment treating available.
I agree I do not want super big pictures on my site, face it in the real world teaching every user to resize a picture before uploading is NOT going to happen so let it go, and if you set limits your just blocking the creativity of the users most the time you aggravate them. Therefore I set my site where it will accept about any size image you can take and it resizes it to 800x600.

For example I set my cell phone to take the biggest pic it can take which is 3264x2448 3.26 meg then add it as a attachment in my phpbb 3.0.12 site after upload its resized to 800x600 and is 94KB I have no idea where the 3.26 meg file went I just know its not stored on my server when my site sends the pics out they are 800x600 94KB as it should be and as I wanted it to behave I never have any complaints from my users about phpbb rejecting attachments.

Now on my test site that is phpbb 3.1.4 I take the same 3264x2448 3.26 meg picture and attach to a post is resized to 800x600 BUT is 887.93 KB not sure what happen and why its not 94KB or close to that size this still needs investigated before I upgrade my 3.0.12 site.

I am not sure your wanting to do that phpbb 3.1.4 can not already do.


For the heck of it I Googled png and found a 1024x768 the file size was 75KB then attached it to a post in the phpbb 3.1.4 it uploaded then converted it to a jpg 800x600 and the filesize increased to 280.66 KB I don't recall the last time someone used a png file on my site I don't see it as a big deal just thought I would test and note since you mention png.
View signatures turned off.

Movie
Registered User
Posts: 127
Joined: Sun Nov 02, 2014 2:54 pm
Location: Chicago Illinois Area.

Re: Attached Images Resizer, Converter & File Size Reducer

Post by Movie » Wed May 27, 2015 12:57 am

Holger wrote:On my sites:
When users post external images/photos by using the IMG-tag we notice this because they are not watermarked with our choosen logo (the watermark is attached when using the forums attachment- or our custom upload-function).

When we (mods/admins) notice the external images we can click on a button (located at the quote-button area) at each post.

When clicking this button the external image/photo is transfered to our servers and saved in a separate folder.

The post is automatically updated and the external IMG-link is replaced with the local one.

Additionally the original link is added as text below the image/photo.

In the settings for posting the user can tick an option that prevents us from copying the image/photo, the one-click-transfer button is then hidden.

Example 1:
In this screenshot you can see the watermark.
No need to do anything because the image was uploaded with one of the forums upload-functions and is saved on our own servers.
Image

Example 2:
In this screenshot you can see NO watermark, it has to be external.
The mods/admins now click on one-click copy button to transfer the image to our own servers.
Image

When clicking the one-click copy button the post also is updated and the external URL is changed to the local, additionally the original URL is added below the image/photo.
Image



- It is important that the users can block the copying of images/photos in the message options!
- The one-click-copy does not work if the IMG-URL is https
- The one-click-copy does not watermark the image/photo
That is a genius idea if I had this option on my site back in 2003 I would not have hundreds of post with missing images on my site, the valuable information they deposited on my site would have been preserved you need to make this option into a Extension please!
View signatures turned off.

didou116
Registered User
Posts: 38
Joined: Wed Jul 22, 2015 3:16 pm

Re: Attached Images Resizer, Converter & File Size Reducer

Post by didou116 » Thu Aug 13, 2015 1:28 pm

Swanny wrote:
][Moon][Shine][ wrote:I have no idea why any admin would NOT want this functionality, as it has only advantages. Why would an admin not want to save bandwidth, server storage space and optimize page load time? Maybe most admins simply don't know about the impact of that feature, but if explained and shown the benefits I guess everybody will want to have it! ;)
+1, I agree 100%.
I agree too. I would definitely love that! I never allowed my users to use attached files because of that but I receive more and more requests about that kind of function. People keep saying that they're tired of using hosting sites like Photobucket when it is so simple to upload images on Facebook for example...
And I'm tired of seeing broken links for images that were posted months or years earlier... Not to mention the fact that I also have to resize images by myself because people just don't want to take time to configure their account...
But I can't afford to use all my storage space for images... So this function would really be great...

Can someone tell me if this is still planned to be developed ?

etsmes
Registered User
Posts: 2
Joined: Wed Mar 18, 2015 9:42 am

Re: Attached Images Resizer, Converter & File Size Reducer

Post by etsmes » Fri Aug 14, 2015 8:54 am

I'm really interested in this extension, as well.

Thanks a lot :!:

rrbailey89
Registered User
Posts: 248
Joined: Fri Oct 24, 2014 3:00 pm

Re: Attached Images Resizer, Converter & File Size Reducer

Post by rrbailey89 » Tue Aug 18, 2015 10:47 pm

Id love to see something like this get off the ground.


User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 16719
Joined: Thu Jan 06, 2005 1:30 pm
Location: Fishkill, NY
Name: David Colón
Contact:

Re: Attached Images Resizer, Converter & File Size Reducer

Post by DavidIQ » Mon Aug 24, 2015 10:38 pm

That's a MOD so pretty useless for the purposes of this topic. :|
Apply to become a Jr. Extension Validator
My extensions | In need of phpBB services? | Was I helpful today?
No unsolicited PMs unless you're planning on asking for paid help.

Post Reply

Return to “Extension Requests”

Who is online

Users browsing this forum: ivailo95, nou nou, sakm and 18 guests