error_reporting(E_ALL | E_NOTICE | E_STRICT | E_WARNING); ini_set('display_errors', 1); define('litepublisher_mode', 'xmlrpc'); include 'index.php'; litepublisher::$debug = true; set_time_limit(300); $p = tmediaparser::i(); if ($p->maxwidth == 0 || $p->maxheight == 0) { die('0 max sizes'); } $files = tfiles::i(); if ($items = $files->db->getitems("media = 'image' and parent = 0 and (width > {$p->maxwidth} or height > {$p->maxheight})")) { echo count($items), ' count<br>'; foreach ($items as $item) { $srcfilename = litepublisher::$paths->files . $item['filename']; if ($source = tmediaparser::readimage($srcfilename)) { $sourcex = imagesx($source); $sourcey = imagesy($source); $x = $p->maxwidth; $y = $p->maxheight; $ratio = $sourcex / $sourcey; if ($x / $y > $ratio) { $x = $y * $ratio; } else { $y = $x / $ratio; } $dest = imagecreatetruecolor($x, $y); imagecopyresampled($dest, $source, 0, 0, 0, 0, $x, $y, $sourcex, $sourcey); imagejpeg($dest, $srcfilename, 95); imagedestroy($dest); @chmod($srcfilename, 0666);
public function uploadlogo($name, $filename, $padding, $height) { if (!($source = tmediaparser::readimage($filename))) { return false; } $sourcex = imagesx($source); $sourcey = imagesy($source); if ($height == $sourcey) { if (!($result = tmediaparser::move_uploaded($name, $filename, 'themegen'))) { return false; } @chmod(litepublisher::$paths->files . str_replace('/', DIRECTORY_SEPARATOR, $result), 0666); return array('url' => litepublisher::$site->files . '/files/' . $result, 'width' => $sourcex + $padding); } $result = tmediaparser::prepare_filename($name, 'themegen'); $realfilename = litepublisher::$paths->files . str_replace('/', DIRECTORY_SEPARATOR, $result); $x = ceil($sourcex * ($height / $sourcey)); $dest = imagecreatetruecolor($x, $height); imagealphablending($dest, false); imagesavealpha($dest, true); $transparent = imagecolorallocatealpha($dest, 255, 255, 255, 127); imagefilledrectangle($dest, 0, 0, $x, $height, $transparent); imagecopyresampled($dest, $source, 0, 0, 0, 0, $x, $height, $sourcex, $sourcey); imagepng($dest, $realfilename); imagedestroy($dest); imagedestroy($source); @chmod($realfilename, 0666); return array('url' => litepublisher::$site->files . '/files/' . $result, 'width' => $x + $padding); }