fix: background removal experimental setting (#307)
This commit is contained in:
parent
36e64263bf
commit
bb5ee2e64c
@ -18,7 +18,7 @@
|
|||||||
return in_array($fileExtension, $allowedExtensions);
|
return in_array($fileExtension, $allowedExtensions);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLogoFromUrl($url, $uploadDir, $name) {
|
function getLogoFromUrl($url, $uploadDir, $name, $settings) {
|
||||||
|
|
||||||
$ch = curl_init($url);
|
$ch = curl_init($url);
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
@ -31,7 +31,7 @@
|
|||||||
$uploadDir = '../../images/uploads/logos/';
|
$uploadDir = '../../images/uploads/logos/';
|
||||||
$uploadFile = $uploadDir . $fileName;
|
$uploadFile = $uploadDir . $fileName;
|
||||||
|
|
||||||
if (saveLogo($imageData, $uploadFile, $name)) {
|
if (saveLogo($imageData, $uploadFile, $name, $settings)) {
|
||||||
return $fileName;
|
return $fileName;
|
||||||
} else {
|
} else {
|
||||||
echo translate('error_fetching_image', $i18n) . ": " . curl_error($ch);
|
echo translate('error_fetching_image', $i18n) . ": " . curl_error($ch);
|
||||||
@ -45,7 +45,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveLogo($imageData, $uploadFile, $name) {
|
function saveLogo($imageData, $uploadFile, $name, $settings) {
|
||||||
$image = imagecreatefromstring($imageData);
|
$image = imagecreatefromstring($imageData);
|
||||||
$removeBackground = isset($settings['removeBackground']) && $settings['removeBackground'] === 'true';
|
$removeBackground = isset($settings['removeBackground']) && $settings['removeBackground'] === 'true';
|
||||||
if ($image !== false) {
|
if ($image !== false) {
|
||||||
@ -71,7 +71,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function resizeAndUploadLogo($uploadedFile, $uploadDir, $name) {
|
function resizeAndUploadLogo($uploadedFile, $uploadDir, $name, $settings) {
|
||||||
$targetWidth = 135;
|
$targetWidth = 135;
|
||||||
$targetHeight = 42;
|
$targetHeight = 42;
|
||||||
|
|
||||||
@ -169,7 +169,7 @@
|
|||||||
$inactive = isset($_POST['inactive']) ? true : false;
|
$inactive = isset($_POST['inactive']) ? true : false;
|
||||||
|
|
||||||
if($logoUrl !== "") {
|
if($logoUrl !== "") {
|
||||||
$logo = getLogoFromUrl($logoUrl, '../../images/uploads/logos/', $name);
|
$logo = getLogoFromUrl($logoUrl, '../../images/uploads/logos/', $name, $settings);
|
||||||
} else {
|
} else {
|
||||||
if (!empty($_FILES['logo']['name'])) {
|
if (!empty($_FILES['logo']['name'])) {
|
||||||
$fileType = mime_content_type($_FILES['logo']['tmp_name']);
|
$fileType = mime_content_type($_FILES['logo']['tmp_name']);
|
||||||
@ -177,7 +177,7 @@
|
|||||||
echo translate("fill_all_fields", $i18n);
|
echo translate("fill_all_fields", $i18n);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
$logo = resizeAndUploadLogo($_FILES['logo'], '../../images/uploads/logos/', $name);
|
$logo = resizeAndUploadLogo($_FILES['logo'], '../../images/uploads/logos/', $name, $settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user