Last active
August 29, 2015 14:25
-
-
Save davidberard98/673be08978d187a0f553 to your computer and use it in GitHub Desktop.
Resize fluxBB profile avatars to allow uploading large files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/******************************* | |
* copyright 2015 David Berard | |
* In profile.php, find the place dealing with $action=='upload_avatar' || $action=='upload_avatar2' | |
* Near the end of the file it writes the image to file. | |
* Once writing to file, use these functions to resize, eg. | |
* gl_resize('/path/to/file', '/path/to/file', '.jpg or .png or .gif') | |
* Also remember to allow large files in administrator settings and large dimensions. | |
* | |
* Must have PHP GD enabled/installed. | |
********************************/ | |
define('GL_IMAGE_SL', 120); | |
function gl_getTheImage($fname, $f_type) | |
{ | |
$ftype = strtolower($f_type); | |
$src_image = false; | |
if($ftype == "jpeg" || $ftype == "jpg" || $ftype==".jpg" || $ftype==".jpeg" || $ftype == "image/jpeg") | |
$src_image = imagecreatefromjpeg($fname); | |
if($ftype == ".png" || $ftype == "png" || $ftype == "image/png") | |
$src_image = imagecreatefrompng($fname); | |
if($ftype == ".gif" || $ftype == "gif" || $ftype == "image/gif") | |
$src_image = imagecreatefromgif($fname); | |
return $src_image; | |
} | |
function gl_imagewrite($fname, $fdata, $f_type) | |
{ | |
//$fname = "/srv/http/fluxBB/img/avatars/abc.jpg"; | |
$ftype = strtolower($f_type); | |
if($ftype == ".jpg" || $ftype == "jpeg" || $ftype == "jpg" || $ftype == "image/jpeg") | |
imagejpeg($fdata, $fname); | |
if($ftype == ".png" || $ftype == "png" || $ftype == "image/png") | |
imagepng($fdata, $fname); | |
if($ftype == ".gif" || $ftype == "gif" || $ftype == "image/gif") | |
imagegif($fdata, $fname); | |
} | |
function gl_resize($fin, $fout, $ftype) | |
{ | |
$src_image = gl_getTheImage($fin, $ftype); | |
$old_x=imageSX($src_image); | |
$old_y=imageSY($src_image); | |
if($old_x <= 120 && $old_y <= 120) | |
{ | |
gl_imagewrite($fout, $src_image, $ftype); | |
} | |
$new_x = $new_y = GL_IMAGE_SL; | |
if($old_x < $new_x) | |
$new_x = $old_x; | |
if($old_y < $new_y) | |
$new_y = $old_y; | |
$dst_img; | |
if($old_x < $old_y) // Smaller dimension to 120 | |
{ | |
$rat_x = GL_IMAGE_SL; | |
$rat_y = intval(GL_IMAGE_SL*$old_x/$old_y); | |
$dst_img=ImageCreateTrueColor($rat_x,$rat_y); | |
imagecopyresampled($dst_img, | |
$src_image, | |
0, 0, // dst x, dst y | |
0, intval(($old_y-$old_x)/2), // src x, src y | |
$new_x, $new_y, | |
$old_x, $old_x); | |
} | |
else | |
{ | |
$rat_y = GL_IMAGE_SL; | |
$rat_x = intval(GL_IMAGE_SL*$old_y/$old_x); | |
//$dst_img=ImageCreateTrueColor($rat_x,$rat_y); | |
$dst_img=ImageCreateTrueColor($new_x, $new_y); | |
imagecopyresampled($dst_img, | |
$src_image, | |
0, 0, // dst x, dst y | |
intval(($old_x-$old_y)/2), 0, // src x, src y | |
//0, 0, // src x, src y | |
$new_x, $new_y, | |
$old_y, $old_y); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment