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)) {
|
||||
$img = new ShowImg($params->type, $params->showImg);
|
||||
$img = new ShowImg($params->type, $params->showImg, $conf->fileFormat);
|
||||
exit();
|
||||
}
|
||||
|
||||
|
@ -182,6 +182,10 @@ class Backend {
|
|||
$uConfig['permitType'] = [];
|
||||
}
|
||||
|
||||
if (!empty($post->fileFormat)) {
|
||||
$uConfig['fileFormat'] = $post->fileFormat;
|
||||
}
|
||||
|
||||
if (!empty($post->password)) {
|
||||
$uConfig['password'] = password_hash($post->password, PASSWORD_DEFAULT);
|
||||
}
|
||||
|
@ -192,6 +196,8 @@ class Backend {
|
|||
|
||||
if (!empty($post->chromePath)) {
|
||||
$uConfig['chromePath'] = $post->chromePath;
|
||||
} else {
|
||||
$uConfig['chromePath'] = '';
|
||||
}
|
||||
|
||||
$uConfig->toFile($userConfig);
|
||||
|
|
|
@ -21,18 +21,18 @@ class GetFav extends GetThumb {
|
|||
|
||||
if (!is_null($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);
|
||||
return true;
|
||||
}
|
||||
} elseif (!is_null($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);
|
||||
return true;
|
||||
}
|
||||
} 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);
|
||||
return true;
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ class GetFav extends GetThumb {
|
|||
//n_print($this);
|
||||
|
||||
//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');
|
||||
echo file_get_contents($this->requestImg);
|
||||
exit();
|
||||
|
|
|
@ -38,7 +38,8 @@ class GetOg extends GetThumb {
|
|||
|
||||
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);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
|
|
|
@ -19,6 +19,7 @@ class GetThumb {
|
|||
protected $conf;
|
||||
protected $db;
|
||||
protected $demande;
|
||||
protected $fileFormat;
|
||||
|
||||
function __construct($params, $conf) {
|
||||
$hmac = new Hmac($conf->key);
|
||||
|
@ -33,13 +34,14 @@ class GetThumb {
|
|||
|
||||
$this->params = $params;
|
||||
$this->type = $params->type;
|
||||
$this->fileFormat = $this->conf->fileFormat;
|
||||
$this->filePath = $hmac->makeFilePath($this->receiveHmac);
|
||||
if ($this->type === 'pdf') {
|
||||
$this->requestImg = $this->filePath . $this->receiveHmac . '_' . $this->type . '.pdf';
|
||||
} 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)[
|
||||
'url' => $this->params->url,
|
||||
|
@ -63,7 +65,7 @@ class GetThumb {
|
|||
echo file_get_contents($this->requestImg);
|
||||
exit();
|
||||
} 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');
|
||||
echo file_get_contents($this->requestImg);
|
||||
exit();
|
||||
|
@ -75,7 +77,7 @@ class GetThumb {
|
|||
'type' => $this->type
|
||||
])) {
|
||||
$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');
|
||||
echo file_get_contents($this->requestImg);
|
||||
exit();
|
||||
|
@ -89,7 +91,7 @@ class GetThumb {
|
|||
'hmac' => $this->params->hmac,
|
||||
'url' => $this->params->url,
|
||||
'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)[
|
||||
|
|
|
@ -28,6 +28,7 @@ class MakeThumb {
|
|||
private $conf;
|
||||
private $db;
|
||||
private $chromePath = '';
|
||||
private $tmpDir = '/tmp/chrome_soshot';
|
||||
|
||||
function __construct() {
|
||||
|
||||
|
@ -111,6 +112,7 @@ class MakeThumb {
|
|||
'keepAlive' => true,
|
||||
'headless' => true,
|
||||
'windowSize' => [1920, 1080],
|
||||
'userDataDir' => $this->tmpDir,
|
||||
'customFlags' => [
|
||||
'--disable-dev-shm-usage',
|
||||
'--disable-gpu'
|
||||
|
@ -144,12 +146,13 @@ class MakeThumb {
|
|||
$page->screenshot([
|
||||
'captureBeyondViewport' => true,
|
||||
'clip' => $page->getFullPageClip(),
|
||||
'format' => $this->conf->fileFormat,
|
||||
])->saveToFile($demande->complete);
|
||||
|
||||
if ($demande->type === 'pdf' || $this->conf->alwaysMakePdf === true) {
|
||||
if ($this->conf->alwaysMakePdf === true) {
|
||||
$pdfFile = str_replace($demande->type, 'pdf', $demande->filePath);
|
||||
$pdfFile = str_replace('png', 'pdf', $pdfFile);
|
||||
$pdfFile = str_replace($this->conf->fileFormat, 'pdf', $pdfFile);
|
||||
} else {
|
||||
$pdfFile = $demande->filePath;
|
||||
}
|
||||
|
@ -187,6 +190,7 @@ class MakeThumb {
|
|||
'keepAlive' => true,
|
||||
'headless' => true,
|
||||
'windowSize' => [1920, 1080],
|
||||
'userDataDir' => $this->tmpDir,
|
||||
'customFlags' => [
|
||||
'--disable-dev-shm-usage',
|
||||
'--disable-gpu'
|
||||
|
|
|
@ -17,8 +17,14 @@ class Page {
|
|||
}
|
||||
|
||||
static function selected($test, $attend) {
|
||||
if (in_array($test, $attend)) {
|
||||
return 'selected';
|
||||
if (is_array($attend)) {
|
||||
if (in_array($test, $attend)) {
|
||||
return 'selected';
|
||||
}
|
||||
} else {
|
||||
if ($test === $attend) {
|
||||
return 'selected';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,11 +6,11 @@ class ShowImg {
|
|||
|
||||
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');
|
||||
|
||||
if (file_exists($img)) {
|
||||
|
|
|
@ -8,5 +8,6 @@
|
|||
"expireCache": 12,
|
||||
"maxGenPerBatch": 5,
|
||||
"icoSize": 48,
|
||||
"chromePath" : ""
|
||||
"chromePath" : "",
|
||||
"fileFormat" : "jpeg"
|
||||
}
|
|
@ -17,7 +17,7 @@ use App\Utils\Page;
|
|||
</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 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>
|
||||
|
||||
<!-- Overlay effect when opening sidebar on small screens -->
|
||||
|
|
|
@ -24,6 +24,13 @@ use App\Utils\Page;
|
|||
<label>Always make PDF</label>
|
||||
<input class="w3-check" type="checkbox" name="alwaysMakePdf" value="1" <?= Page::checked($this->conf->alwaysMakePdf, true); ?>>
|
||||
</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>
|
||||
<label>Favicon size</label>
|
||||
<input class="w3-input w3-border" type="number" name="icoSize" value="<?= $this->conf->icoSize; ?>">
|
||||
|
@ -66,7 +73,7 @@ use App\Utils\Page;
|
|||
|
||||
<p>
|
||||
<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>
|
||||
</p>
|
||||
</form>
|
||||
|
|
Loading…
Reference in a new issue