Hi,
Recently I setup a site using GForum, where people were used to uploading huge images ... so ended up having to make a hack into /admin/GForum/Post/Write.pm, so that gif/jpg images would automatically be shrunk down to a more reasonable size.
Here is a quick how-to:
In /admin/GForum/Post/Write.pm, find sub attachment_upload {, and then in that function. find:
$STASH{tpl_vars}->{attachment_uploaded} = $filename;
$STASH{tpl_vars}->{attachment_uploaded_id} = $sth->insert_id;
}
Change this to:
$STASH{tpl_vars}->{attachment_uploaded} = $filename;
$STASH{tpl_vars}->{attachment_uploaded_id} = $sth->insert_id;
# Mod by andy..,
shrink_image($STASH{tpl_vars}->{attachment_uploaded_id});
}
Then add the below function :
my $attachment_id = $_[0];
my $file_stats = $DB->table("TempAttachment")->select( { tempatt_id => $attachment_id } )->fetchrow_hashref;
# print $IN->header;
#use Data::Dumper;
#print Dumper($file_stats);
if ($file_stats->{tempatt_content} eq "image/gif" || $file_stats->{tempatt_content} eq "image/jpeg") {
my $fletter = ( reverse split //, $file_stats->{tempatt_id} )[0];
my $path = "$CFG->{admin_root_path}/attachments/temp/$fletter/$file_stats->{tempatt_id}";
use Image::Size;
my ($x,$y) = imgsize($path);
if ($x > 700 || $y > 700) {
my $command = qq~convert '$path' -resize 700x700 ${path}.new~;
`$command`;
my $command2 = qq|rm -f $path|;
`$command2`;
my $command3 = qq~mv ${path}.new $path~;
`$command3`;
my $size = -s $path;
my $attach = $DB->table('TempAttachment');
$attach->update( { tempatt_size => $size } , { tempatt_id => $attachment_id } ) || die $GT::SQL::error;
}
}
}
That should do it
When you do an inline image, or attachment - it should shrink down the image to 700x700 max (assuming its larger than 700x700 :))
Enjoy!
Cheers
Andy (mod)
andy@ultranerds.co.uk
IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Recently I setup a site using GForum, where people were used to uploading huge images ... so ended up having to make a hack into /admin/GForum/Post/Write.pm, so that gif/jpg images would automatically be shrunk down to a more reasonable size.
Here is a quick how-to:
In /admin/GForum/Post/Write.pm, find sub attachment_upload {, and then in that function. find:
Code:
else { $STASH{tpl_vars}->{attachment_uploaded} = $filename;
$STASH{tpl_vars}->{attachment_uploaded_id} = $sth->insert_id;
}
Change this to:
Code:
else { $STASH{tpl_vars}->{attachment_uploaded} = $filename;
$STASH{tpl_vars}->{attachment_uploaded_id} = $sth->insert_id;
# Mod by andy..,
shrink_image($STASH{tpl_vars}->{attachment_uploaded_id});
}
Then add the below function :
Code:
sub shrink_image { my $attachment_id = $_[0];
my $file_stats = $DB->table("TempAttachment")->select( { tempatt_id => $attachment_id } )->fetchrow_hashref;
# print $IN->header;
#use Data::Dumper;
#print Dumper($file_stats);
if ($file_stats->{tempatt_content} eq "image/gif" || $file_stats->{tempatt_content} eq "image/jpeg") {
my $fletter = ( reverse split //, $file_stats->{tempatt_id} )[0];
my $path = "$CFG->{admin_root_path}/attachments/temp/$fletter/$file_stats->{tempatt_id}";
use Image::Size;
my ($x,$y) = imgsize($path);
if ($x > 700 || $y > 700) {
my $command = qq~convert '$path' -resize 700x700 ${path}.new~;
`$command`;
my $command2 = qq|rm -f $path|;
`$command2`;
my $command3 = qq~mv ${path}.new $path~;
`$command3`;
my $size = -s $path;
my $attach = $DB->table('TempAttachment');
$attach->update( { tempatt_size => $size } , { tempatt_id => $attachment_id } ) || die $GT::SQL::error;
}
}
}
That should do it
When you do an inline image, or attachment - it should shrink down the image to 700x700 max (assuming its larger than 700x700 :))
Enjoy!
Cheers
Andy (mod)
andy@ultranerds.co.uk
IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates

