Files
AtomicOld/resize/resize_page_gallery.php

138 lines
3.7 KiB
PHP
Raw Permalink Normal View History

2026-02-14 19:34:54 +03:00
<?php
$width = 210;
$height = 150;
$filename = $_GET['file'];
$ext = mb_strtolower(substr(strrchr($filename, '.'), 1));
if($ext != 'png'){
chdir('..');
require_once ('api/Simpla.php');
//$token = $_GET['token'];
$filename = str_replace('%2F', '/', $filename);
if (substr($filename, 0, 6) == 'http:/')
$filename = 'http://' . substr($filename, 6);
$simpla = new Simpla();
//if (!$simpla->config->check_token($filename, $token)){ exit('bad token'); }
$donefilename = $simpla->image->add_resize_params($filename, $width, $height, $set_watermark);
if (is_readable('' . $donefilename))
{ $resized_filename = $simpla->config->categories_images_dir . $donefilename;}
else
{$resized_filename = $simpla->image->resizecat($filename);}
///echo $resized_filename.'---88';
///exit();
$resized_filename = ltrim($resized_filename,'/');
$name = substr($filename, 0, -strlen(strrchr ($filename, ".")));
if (is_readable($resized_filename) && $name != 'audi' && $name != 'dodge')
{
header('Content-type: image');
echo file_get_contents($_SERVER['DOCUMENT_ROOT'].'/'.$resized_filename);
exit;
}
exit;
}
$filename = $_GET['file'];
$ext = mb_strtolower(substr(strrchr($filename, '.'), 1));
$name = substr($filename, 0, -strlen(strrchr ($filename, ".")));
$resized_filename = 'files/categories/'.$name.'.'.$width.'x'.$height.'.jpg';
$info = getimagesize($_SERVER['DOCUMENT_ROOT'].'/files/brands/'.$filename);
$default = 'h';
$info = array(
'width' => $info[0],
'height' => $info[1],
);
if($info['width'] < $width) echoimg($_SERVER['DOCUMENT_ROOT'].'/files/brands/'.$filename);
if(file_exists($_SERVER['DOCUMENT_ROOT'].'/'.$resized_filename)) echoimg($_SERVER['DOCUMENT_ROOT'].'/'.$resized_filename);
$image = '';
if ($ext == 'gif') $image = imagecreatefromgif($_SERVER['DOCUMENT_ROOT'].'/files/brands/'.$filename);
if ($ext == 'png') $image = imagecreatefrompng($_SERVER['DOCUMENT_ROOT'].'/files/brands/'.$filename);
if(!$image) $image = imagecreatefromjpeg($_SERVER['DOCUMENT_ROOT'].'/files/brands/'.$filename);
$xpos = 0;
$ypos = 0;
$scale = 1;
$scale_w = $width / $info['width'];
$scale_h = $height / $info['height'];
if ($default == 'w') {
$scale = $scale_w;
} elseif ($default == 'h'){
$scale = $scale_h;
} else {
$scale = min($scale_w, $scale_h);
}
if ($scale == 1 && $scale_h == $scale_w) {
echoimg($_SERVER['DOCUMENT_ROOT'].'/files/brands/'.$filename);
}
// $new_width = (int)($info['width'] * $scale);
// $new_height = (int)($info['height'] * $scale);
$new_width = $width;
$new_height = (int)($info['height']/($info['width']/$width));
//print_r($info); echo $new_height.'x'.$new_width; exit;
$xpos = (int)(($width - $new_width) / 2);
$ypos = (int)(($height - $new_height) / 2);
$image_old = $image;
$image = imagecreatetruecolor($width, $height);
/*
if ($ext == 'png') {
imagealphablending($this->image, false);
imagesavealpha($this->image, true);
$background = imagecolorallocatealpha($this->image, 255, 255, 255, 127);
imagecolortransparent($this->image, $background);
} else {
$background = imagecolorallocate($this->image, 255, 255, 255);
}
*/
$background = imagecolorallocate($image, 28, 30, 44);
imagefilledrectangle($image, 0, 0, $width, $height, $background);
imagecopyresampled($image, $image_old, $xpos, $ypos, 0, 0, $new_width, $new_height, $info['width'], $info['height']);
imagedestroy($image_old);
imagejpeg($image, $_SERVER['DOCUMENT_ROOT'].'/'.$resized_filename, 80);
imagedestroy($image);
echoimg($_SERVER['DOCUMENT_ROOT'].'/'.$resized_filename);
function echoimg($src){
header('Content-type: image');
echo file_get_contents($src);
exit;
}