Merge pull request #11 from mt-admin mysqli...
Merge pull request #11 from mt-admin mysqli Convert the admin backend to the more modern MySQLi driver.

File last commit:

c3da001f5ff1
dc6672c2e0e6 merge
Show More
images.php
57 lines | 1.2 KiB | text/x-php | PhpLexer
Add most necessary files for admin interface.
r1 <?php
function getimagefromfile($filename)
{
$img_data = getimagesize($filename);
$ext = image_type_to_extension($img_data[2]);
Fix calls to mysqli_error().
r7
Add most necessary files for admin interface.
r1 switch($ext)
{
case '.gif':
return imagecreatefromgif($filename);
break;
case '.jpg':
case '.jpeg':
return imagecreatefromjpeg($filename);
break;
case '.png':
return imagecreatefrompng($filename);
break;
default:
return false;
}
}
function crop_resize($filename, $dest_file)
{
#REQUIRES: image be at least 300x245
$source = getimagefromfile($filename);
if(!$source)
{
return false;
}
$dest = imagecreatetruecolor(300, 245);
Fix calls to mysqli_error().
r7
Add most necessary files for admin interface.
r1 #attempt to determine scaling factor
$data = getimagesize($filename);
#300x245 reduces to 60x49
$factor = min(floor($data[0]/60), floor($data[1]/49));
#well, that should give us a good scaling factor
Fix calls to mysqli_error().
r7
Add most necessary files for admin interface.
r1 #now we have to determine what point to start from
$src_x = floor(($data[0]/2) - ($factor*30));
$src_y = floor(($data[1]/2) - ($factor*24.5));
Fix calls to mysqli_error().
r7
Add most necessary files for admin interface.
r1 #make sure we don't fuck things up
if($src_x < 0) $src_x=0;
if($src_y < 0) $src_y=0;
Fix calls to mysqli_error().
r7
Add most necessary files for admin interface.
r1 #now resample
imagecopyresampled($dest, $source, 0, 0, $src_x, $src_y, 300, 245, $factor*60, $factor*49);
#and output
imagepng($dest, $dest_file);
return true;
}
?>