Add select img format type (jpeg, png)
This commit is contained in:
parent
78ec0fc074
commit
89a5f95b71
10 changed files with 47 additions and 20 deletions
|
@ -45,7 +45,7 @@ class Backend {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($params->showImg)) {
|
if (!empty($params->showImg)) {
|
||||||
$img = new ShowImg($params->type, $params->showImg);
|
$img = new ShowImg($params->type, $params->showImg, $conf->fileFormat);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,6 +182,10 @@ class Backend {
|
||||||
$uConfig['permitType'] = [];
|
$uConfig['permitType'] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($post->fileFormat)) {
|
||||||
|
$uConfig['fileFormat'] = $post->fileFormat;
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($post->password)) {
|
if (!empty($post->password)) {
|
||||||
$uConfig['password'] = password_hash($post->password, PASSWORD_DEFAULT);
|
$uConfig['password'] = password_hash($post->password, PASSWORD_DEFAULT);
|
||||||
}
|
}
|
||||||
|
@ -192,6 +196,8 @@ class Backend {
|
||||||
|
|
||||||
if (!empty($post->chromePath)) {
|
if (!empty($post->chromePath)) {
|
||||||
$uConfig['chromePath'] = $post->chromePath;
|
$uConfig['chromePath'] = $post->chromePath;
|
||||||
|
} else {
|
||||||
|
$uConfig['chromePath'] = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$uConfig->toFile($userConfig);
|
$uConfig->toFile($userConfig);
|
||||||
|
|
|
@ -21,18 +21,18 @@ class GetFav extends GetThumb {
|
||||||
|
|
||||||
if (!is_null($info->favicon)) {
|
if (!is_null($info->favicon)) {
|
||||||
if (!$favicon = @file_get_contents($info->favicon)) {
|
if (!$favicon = @file_get_contents($info->favicon)) {
|
||||||
copy(__DIR__ . '/../../src/images/error_fav.png', $this->demande->requestImg);
|
copy(__DIR__ . '/../../src/images/error_fav.'.$this->fileFormat, $this->demande->requestImg);
|
||||||
$this->db->addUpdate(2);
|
$this->db->addUpdate(2);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} elseif (!is_null($info->icon)) {
|
} elseif (!is_null($info->icon)) {
|
||||||
if (!$favicon = @file_get_contents($info->icon)) {
|
if (!$favicon = @file_get_contents($info->icon)) {
|
||||||
copy(__DIR__ . '/../../src/images/error_fav.png', $this->demande->requestImg);
|
copy(__DIR__ . '/../../src/images/error_fav.'.$this->fileFormat, $this->demande->requestImg);
|
||||||
$this->db->addUpdate(2);
|
$this->db->addUpdate(2);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
copy(__DIR__ . '/../../src/images/error_fav.png', $this->demande->requestImg);
|
copy(__DIR__ . '/../../src/images/error_fav.'.$this->fileFormat, $this->demande->requestImg);
|
||||||
$this->db->addUpdate(2);
|
$this->db->addUpdate(2);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ class GetFav extends GetThumb {
|
||||||
//n_print($this);
|
//n_print($this);
|
||||||
|
|
||||||
//echo '<img src="data:image/png;base64,'.base64_encode(file_get_contents($this->requestImg)).'">';
|
//echo '<img src="data:image/png;base64,'.base64_encode(file_get_contents($this->requestImg)).'">';
|
||||||
header("Content-type: image/png");
|
header("Content-type: image/$this->fileFormat");
|
||||||
header('Expires: ', gmdate('D, d M Y H:i:s', time()) . ' GMT');
|
header('Expires: ', gmdate('D, d M Y H:i:s', time()) . ' GMT');
|
||||||
echo file_get_contents($this->requestImg);
|
echo file_get_contents($this->requestImg);
|
||||||
exit();
|
exit();
|
||||||
|
|
|
@ -38,7 +38,8 @@ class GetOg extends GetThumb {
|
||||||
|
|
||||||
file_put_contents($this->demande->requestImg, $image);
|
file_put_contents($this->demande->requestImg, $image);
|
||||||
|
|
||||||
if (in_array(mime_content_type($this->demande->requestImg), ['image/jpg', 'image/jpeg', 'image/bmp', 'image/webp'])) {
|
if (in_array(mime_content_type($this->demande->requestImg), ['image/jpg', 'image/jpeg', 'image/bmp', 'image/webp']) && $this->fileFormat === 'png') {
|
||||||
|
// @todo convertToWebp convertToJpg
|
||||||
ConvertToPng::convertToPng($this->demande);
|
ConvertToPng::convertToPng($this->demande);
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|
|
@ -19,6 +19,7 @@ class GetThumb {
|
||||||
protected $conf;
|
protected $conf;
|
||||||
protected $db;
|
protected $db;
|
||||||
protected $demande;
|
protected $demande;
|
||||||
|
protected $fileFormat;
|
||||||
|
|
||||||
function __construct($params, $conf) {
|
function __construct($params, $conf) {
|
||||||
$hmac = new Hmac($conf->key);
|
$hmac = new Hmac($conf->key);
|
||||||
|
@ -33,13 +34,14 @@ class GetThumb {
|
||||||
|
|
||||||
$this->params = $params;
|
$this->params = $params;
|
||||||
$this->type = $params->type;
|
$this->type = $params->type;
|
||||||
|
$this->fileFormat = $this->conf->fileFormat;
|
||||||
$this->filePath = $hmac->makeFilePath($this->receiveHmac);
|
$this->filePath = $hmac->makeFilePath($this->receiveHmac);
|
||||||
if ($this->type === 'pdf') {
|
if ($this->type === 'pdf') {
|
||||||
$this->requestImg = $this->filePath . $this->receiveHmac . '_' . $this->type . '.pdf';
|
$this->requestImg = $this->filePath . $this->receiveHmac . '_' . $this->type . '.pdf';
|
||||||
} else {
|
} else {
|
||||||
$this->requestImg = $this->filePath . $this->receiveHmac . '_' . $this->type . '.png';
|
$this->requestImg = $this->filePath . $this->receiveHmac . '_' . $this->type . '.'.$this->fileFormat;
|
||||||
}
|
}
|
||||||
$this->complete = __DIR__ . '/../../cache/img/' . substr($this->params->hmac, 0, 4) . '/' . $this->params->hmac . '_complete.png';
|
$this->complete = __DIR__ . '/../../cache/img/' . substr($this->params->hmac, 0, 4) . '/' . $this->params->hmac . '_complete.'.$this->fileFormat;
|
||||||
|
|
||||||
$this->demande = (object)[
|
$this->demande = (object)[
|
||||||
'url' => $this->params->url,
|
'url' => $this->params->url,
|
||||||
|
@ -63,7 +65,7 @@ class GetThumb {
|
||||||
echo file_get_contents($this->requestImg);
|
echo file_get_contents($this->requestImg);
|
||||||
exit();
|
exit();
|
||||||
} else if (file_exists($this->requestImg) && in_array($this->type, ['complete', 'full', 'hd', 'thumb'])) {
|
} else if (file_exists($this->requestImg) && in_array($this->type, ['complete', 'full', 'hd', 'thumb'])) {
|
||||||
header("Content-type: image/png");
|
header("Content-type: image/$this->fileFormat");
|
||||||
header('Expires: ', gmdate('D, d M Y H:i:s', time()) . ' GMT');
|
header('Expires: ', gmdate('D, d M Y H:i:s', time()) . ' GMT');
|
||||||
echo file_get_contents($this->requestImg);
|
echo file_get_contents($this->requestImg);
|
||||||
exit();
|
exit();
|
||||||
|
@ -75,7 +77,7 @@ class GetThumb {
|
||||||
'type' => $this->type
|
'type' => $this->type
|
||||||
])) {
|
])) {
|
||||||
$this->db->addUpdate(1);
|
$this->db->addUpdate(1);
|
||||||
header("Content-type: image/png");
|
header("Content-type: image/$this->fileFormat");
|
||||||
header('Expires: ', gmdate('D, d M Y H:i:s', time()) . ' GMT');
|
header('Expires: ', gmdate('D, d M Y H:i:s', time()) . ' GMT');
|
||||||
echo file_get_contents($this->requestImg);
|
echo file_get_contents($this->requestImg);
|
||||||
exit();
|
exit();
|
||||||
|
@ -89,7 +91,7 @@ class GetThumb {
|
||||||
'hmac' => $this->params->hmac,
|
'hmac' => $this->params->hmac,
|
||||||
'url' => $this->params->url,
|
'url' => $this->params->url,
|
||||||
'filePath' => $this->requestImg,
|
'filePath' => $this->requestImg,
|
||||||
'complete' => __DIR__ . '/../../cache/img/' . substr($this->params->hmac, 0, 4) . '/' . $this->params->hmac . '_complete.png'
|
'complete' => __DIR__ . '/../../cache/img/' . substr($this->params->hmac, 0, 4) . '/' . $this->params->hmac . '_complete.'.$this->fileFormat
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$completeDemande = (object)[
|
$completeDemande = (object)[
|
||||||
|
|
|
@ -28,6 +28,7 @@ class MakeThumb {
|
||||||
private $conf;
|
private $conf;
|
||||||
private $db;
|
private $db;
|
||||||
private $chromePath = '';
|
private $chromePath = '';
|
||||||
|
private $tmpDir = '/tmp/chrome_soshot';
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
|
|
||||||
|
@ -111,6 +112,7 @@ class MakeThumb {
|
||||||
'keepAlive' => true,
|
'keepAlive' => true,
|
||||||
'headless' => true,
|
'headless' => true,
|
||||||
'windowSize' => [1920, 1080],
|
'windowSize' => [1920, 1080],
|
||||||
|
'userDataDir' => $this->tmpDir,
|
||||||
'customFlags' => [
|
'customFlags' => [
|
||||||
'--disable-dev-shm-usage',
|
'--disable-dev-shm-usage',
|
||||||
'--disable-gpu'
|
'--disable-gpu'
|
||||||
|
@ -144,12 +146,13 @@ class MakeThumb {
|
||||||
$page->screenshot([
|
$page->screenshot([
|
||||||
'captureBeyondViewport' => true,
|
'captureBeyondViewport' => true,
|
||||||
'clip' => $page->getFullPageClip(),
|
'clip' => $page->getFullPageClip(),
|
||||||
|
'format' => $this->conf->fileFormat,
|
||||||
])->saveToFile($demande->complete);
|
])->saveToFile($demande->complete);
|
||||||
|
|
||||||
if ($demande->type === 'pdf' || $this->conf->alwaysMakePdf === true) {
|
if ($demande->type === 'pdf' || $this->conf->alwaysMakePdf === true) {
|
||||||
if ($this->conf->alwaysMakePdf === true) {
|
if ($this->conf->alwaysMakePdf === true) {
|
||||||
$pdfFile = str_replace($demande->type, 'pdf', $demande->filePath);
|
$pdfFile = str_replace($demande->type, 'pdf', $demande->filePath);
|
||||||
$pdfFile = str_replace('png', 'pdf', $pdfFile);
|
$pdfFile = str_replace($this->conf->fileFormat, 'pdf', $pdfFile);
|
||||||
} else {
|
} else {
|
||||||
$pdfFile = $demande->filePath;
|
$pdfFile = $demande->filePath;
|
||||||
}
|
}
|
||||||
|
@ -187,6 +190,7 @@ class MakeThumb {
|
||||||
'keepAlive' => true,
|
'keepAlive' => true,
|
||||||
'headless' => true,
|
'headless' => true,
|
||||||
'windowSize' => [1920, 1080],
|
'windowSize' => [1920, 1080],
|
||||||
|
'userDataDir' => $this->tmpDir,
|
||||||
'customFlags' => [
|
'customFlags' => [
|
||||||
'--disable-dev-shm-usage',
|
'--disable-dev-shm-usage',
|
||||||
'--disable-gpu'
|
'--disable-gpu'
|
||||||
|
|
|
@ -17,9 +17,15 @@ class Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
static function selected($test, $attend) {
|
static function selected($test, $attend) {
|
||||||
|
if (is_array($attend)) {
|
||||||
if (in_array($test, $attend)) {
|
if (in_array($test, $attend)) {
|
||||||
return 'selected';
|
return 'selected';
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if ($test === $attend) {
|
||||||
|
return 'selected';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static function genToken() {
|
static function genToken() {
|
||||||
|
|
|
@ -6,11 +6,11 @@ class ShowImg {
|
||||||
|
|
||||||
private $thumbPath = __DIR__ . '/../../cache/img/';
|
private $thumbPath = __DIR__ . '/../../cache/img/';
|
||||||
|
|
||||||
function __construct($type, $hmac) {
|
function __construct($type, $hmac, $fileFormat) {
|
||||||
|
|
||||||
$img = $this->thumbPath . substr($hmac, 0, 4) . '/' . $hmac . '_' . $type . '.png';
|
$img = $this->thumbPath . substr($hmac, 0, 4) . '/' . $hmac . '_' . $type . '.'.$fileFormat;
|
||||||
|
|
||||||
header("Content-type: image/png");
|
header("Content-type: image/$fileFormat");
|
||||||
header('Expires: ', gmdate('D, d M Y H:i:s', time()) . ' GMT');
|
header('Expires: ', gmdate('D, d M Y H:i:s', time()) . ' GMT');
|
||||||
|
|
||||||
if (file_exists($img)) {
|
if (file_exists($img)) {
|
||||||
|
|
|
@ -8,5 +8,6 @@
|
||||||
"expireCache": 12,
|
"expireCache": 12,
|
||||||
"maxGenPerBatch": 5,
|
"maxGenPerBatch": 5,
|
||||||
"icoSize": 48,
|
"icoSize": 48,
|
||||||
"chromePath" : ""
|
"chromePath" : "",
|
||||||
|
"fileFormat" : "jpeg"
|
||||||
}
|
}
|
|
@ -17,7 +17,7 @@ use App\Utils\Page;
|
||||||
</a>
|
</a>
|
||||||
<a class="w3-bar-item w3-button <?= Page::active($params->page, 'infos', 'w3-gray') ?>" href="?page=infos"> <i class="fa fa-info"></i> Infos</a>
|
<a class="w3-bar-item w3-button <?= Page::active($params->page, 'infos', 'w3-gray') ?>" href="?page=infos"> <i class="fa fa-info"></i> Infos</a>
|
||||||
<a class="w3-bar-item w3-button <?= Page::active($params->page, 'settings', 'w3-gray') ?>" href="?page=settings"><i class="fa fa-cog"></i> Settings</a>
|
<a class="w3-bar-item w3-button <?= Page::active($params->page, 'settings', 'w3-gray') ?>" href="?page=settings"><i class="fa fa-cog"></i> Settings</a>
|
||||||
<a class="w3-bar-item w3-button w3-margin-top <?= Page::active($params->page, 'logout', 'w3-gray') ?>" href="/logout"><i class="fa fa-cog"></i> Logout</a>
|
<a class="w3-bar-item w3-button w3-margin-top <?= Page::active($params->page, 'logout', 'w3-gray') ?>" href="/logout"><i class="fa fa-sign-out"></i> Logout</a>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<!-- Overlay effect when opening sidebar on small screens -->
|
<!-- Overlay effect when opening sidebar on small screens -->
|
||||||
|
|
|
@ -24,6 +24,13 @@ use App\Utils\Page;
|
||||||
<label>Always make PDF</label>
|
<label>Always make PDF</label>
|
||||||
<input class="w3-check" type="checkbox" name="alwaysMakePdf" value="1" <?= Page::checked($this->conf->alwaysMakePdf, true); ?>>
|
<input class="w3-check" type="checkbox" name="alwaysMakePdf" value="1" <?= Page::checked($this->conf->alwaysMakePdf, true); ?>>
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
<label>File format (png, jpeg)</label>
|
||||||
|
<select class="w3-select w3-border" name="fileFormat" size="2">
|
||||||
|
<option value="png" <?= Page::selected('png', $this->conf->fileFormat); ?>>png</option>
|
||||||
|
<option value="jpeg" <?= Page::selected('jpeg', $this->conf->fileFormat); ?>>jpeg</option>
|
||||||
|
</select>
|
||||||
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<label>Favicon size</label>
|
<label>Favicon size</label>
|
||||||
<input class="w3-input w3-border" type="number" name="icoSize" value="<?= $this->conf->icoSize; ?>">
|
<input class="w3-input w3-border" type="number" name="icoSize" value="<?= $this->conf->icoSize; ?>">
|
||||||
|
@ -66,7 +73,7 @@ use App\Utils\Page;
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<input type="hidden" name="page" value="settings">
|
<input type="hidden" name="page" value="settings">
|
||||||
<input type="hidden" name="token" value="<?= $token;?>">
|
<input type="hidden" name="token" value="<?= $token; ?>">
|
||||||
<button type="submit" class="w3-btn w3-padding w3-teal" style="width:120px">Save</button>
|
<button type="submit" class="w3-btn w3-padding w3-teal" style="width:120px">Save</button>
|
||||||
</p>
|
</p>
|
||||||
</form>
|
</form>
|
||||||
|
|
Loading…
Reference in a new issue