Resize avatar image if too large 🌆 (#1512)

* Resize avatar image if too large 🌆

* Update CHANGELOG.md
This commit is contained in:
Roman Kelesidis 2024-06-14 14:51:19 +07:00 committed by GitHub
commit f1665f5155
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 2 deletions

View file

@ -6,6 +6,7 @@
**Merged pull requests:** **Merged pull requests:**
- Release 2.4.4 🦩 ([belomaxorka](https://github.com/belomaxorka)) - Release 2.4.4 🦩 ([belomaxorka](https://github.com/belomaxorka))
- Resize avatar image if too large 🌆 [\#1512](https://github.com/torrentpier/torrentpier/pull/1512) ([belomaxorka](https://github.com/belomaxorka))
- Increased PASSWORD_MAX_LENGTH [\#1510](https://github.com/torrentpier/torrentpier/pull/1510) ([belomaxorka](https://github.com/belomaxorka)) - Increased PASSWORD_MAX_LENGTH [\#1510](https://github.com/torrentpier/torrentpier/pull/1510) ([belomaxorka](https://github.com/belomaxorka))
- Some security improvements 🔑 [\#1503](https://github.com/torrentpier/torrentpier/pull/1503) ([belomaxorka](https://github.com/belomaxorka)) - Some security improvements 🔑 [\#1503](https://github.com/torrentpier/torrentpier/pull/1503) ([belomaxorka](https://github.com/belomaxorka))
- Some security enhancements (Part 2) [\#1505](https://github.com/torrentpier/torrentpier/pull/1505) ([belomaxorka](https://github.com/belomaxorka)) - Some security enhancements (Part 2) [\#1505](https://github.com/torrentpier/torrentpier/pull/1505) ([belomaxorka](https://github.com/belomaxorka))

View file

@ -161,9 +161,23 @@ class Upload
// width & height // width & height
if (($this->cfg['max_width'] && $width > $this->cfg['max_width']) || ($this->cfg['max_height'] && $height > $this->cfg['max_height'])) { if (($this->cfg['max_width'] && $width > $this->cfg['max_width']) || ($this->cfg['max_height'] && $height > $this->cfg['max_height'])) {
for ($i = 0, $max_try = 3; $i <= $max_try; $i++) {
try {
$image = new \claviska\SimpleImage();
$image
->fromFile($this->file['tmp_name'])
->autoOrient()
->resize($this->cfg['max_width'], $this->cfg['max_height'])
->toFile($this->file['tmp_name']);
break;
} catch (\Exception $e) {
if ($i == $max_try) {
$this->errors[] = sprintf($lang['UPLOAD_ERROR_DIMENSIONS'], $this->cfg['max_width'], $this->cfg['max_height']); $this->errors[] = sprintf($lang['UPLOAD_ERROR_DIMENSIONS'], $this->cfg['max_width'], $this->cfg['max_height']);
return false; return false;
} }
}
}
}
} else { } else {
$this->errors[] = $lang['UPLOAD_ERROR_NOT_IMAGE']; $this->errors[] = $lang['UPLOAD_ERROR_NOT_IMAGE'];
return false; return false;