Warning: chmod(): Operation not permitted in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [0] in function chmod in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [1] in function include_once in /var/www/hopeinstoughton_www/wp-settings.php on line 560 [2] in function require_once in /var/www/hopeinstoughton_www/wp-config.php on line 85 [3] in function require_once in /var/www/hopeinstoughton_www/wp-load.php on line 50 [4] in function require_once in /var/www/hopeinstoughton_www/wp-blog-header.php on line 13 [5] in function require in /var/www/hopeinstoughton_www/index.php on line 17
| Server IP : 94.177.8.99 / Your IP : 216.73.217.165 Web Server : Apache/2.4.58 (Ubuntu) System : Linux aries 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64 User : www-data ( 33) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/hopeinstoughton_books/core/models/ |
Upload File : |
<?php
class Thumbnail_Model extends Model {
// this is the function that will create the thumbnail image from the uploaded image
// the resize will be done considering the width and height defined, but without deforming the image
function _make_thumb($img_name, $new_w, $new_h, &$DATA) {
$dim = getimagesize($img_name);
switch($dim[2]) {
case IMAGETYPE_JPEG:
$src_img=@imagecreatefromjpeg($img_name);
break;
case IMAGETYPE_PNG:
$src_img=imagecreatefrompng($img_name);
break;
case IMAGETYPE_GIF:
$src_img=imagecreatefromgif($img_name);
$trans = imageColorTransparent($src_img);
if ($trans >= 0) {
$old_x = imagesx($src_img); $old_y = imagesy($src_img);
$bg = imagecolorallocate($src_img, 255, 255, 255);
for($y = $old_y - 1; $y >= 0; $y--) {
for($x = $old_x - 1; $x >= 0; $x--) {
if (imagecolorat($src_img, $x, $y) == $trans) {
imageSetPixel($src_img, $x, $y, $bg);
}
}
}
}
break;
}
$old_x = @imagesx($src_img); $old_y = @imagesy($src_img);
if (!$old_x) { // the source image is corrupted
return 1;
}
$ratio1 = $old_x / $new_w;
$ratio2 = $old_y / $new_h;
if ($ratio1 > $ratio2) {
$thumb_w=$new_w;
$thumb_h=intval($old_y/$ratio1);
} else {
$thumb_h=$new_h;
$thumb_w=intval($old_x/$ratio2);
}
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
$tmpfname = tempnam('/tmp', 'ign');
imagejpeg($dst_img,$tmpfname); // Save as JPEG
imagedestroy($dst_img);
imagedestroy($src_img);
$thumb = file_get_contents($tmpfname);
unlink($tmpfname);
$dim = array('tp' => IMAGETYPE_JPEG, 'wd' => $thumb_w, 'ht' => $thumb_h, 'dt' => time());
$DATA['bt_cover'] = base64_encode($thumb);
$DATA['bt_dim'] = serialize($dim);
return 0;
}
public function RemoveImage($n) {
global $DATABASE;
$n = intval($n);
$DATABASE->Query("update dt_title set bt_dim='',bt_cover='' where bt_id=%d", $n, '', 0);
DbErr($DATABASE);
}
public function AttachImage(&$DATA, $filename) {
$maxh = 450;
$max = intval($maxh / 1.2);
self::_make_thumb($filename, $max, $maxh, $DATA); // now create the thumbnail
}
}