Fichier WEBP, SVG, JPEG

Salut,

Lorsqu’on choisi une image pour les objets, notre choix est limité au format JPG, GIF et PNG.
L’ajout des format SVG et WEBP permettrait l’utilisation d’images de meilleur qualité ou de taille vraiment réduite en fonctions des besoins.

Jeedom les affiches sans soucis, seul manque la possibilité de les importer.

En modifiant dans le core le fichier object.ajax.php les lignes 291 et 292 de uploadImage :

	if (init('action') == 'uploadImage') {
		if (!isConnect('admin')) {
			throw new Exception(__('401 - Accès non autorisé', __FILE__));
		}
		unautorizedInDemo();
		$object = jeeObject::byId(init('id'));
		if (!is_object($object)) {
			throw new Exception(__('Objet inconnu. Vérifiez l\'ID', __FILE__));
		}
		if (init('file') == '') {
			if (!isset($_FILES['file'])) {
				throw new Exception(__('Aucun fichier trouvé. Vérifiez le paramètre PHP (post size limit)', __FILE__));
			}
			$extension = strtolower(strrchr($_FILES['file']['name'], '.'));
			if (!in_array($extension, array('.jpg', '.png', '.gif', '.svg', '.webp'))) {
				throw new Exception(__('Extension du fichier non valide (autorisé .jpg .png .gif .svg .webp) :', __FILE__) . ' ' . $extension);
			}
			if (filesize($_FILES['file']['tmp_name']) > 5000000) {
				throw new Exception(__('Le fichier est trop gros (maximum 5Mo)', __FILE__));
			}
			$upfilepath = $_FILES['file']['tmp_name'];
		} else {
			$extension = strtolower(strrchr(init('file'), '.'));
			$upfilepath = init('file');
		}
		$files = ls(__DIR__ . '/../../data/object/', 'object' . $object->getId() . '-*');

		if (count($files)  > 0) {
			foreach ($files as $file) {
				unlink(__DIR__ . '/../../data/object/' . $file);
			}
		}
		$object->setImage('type', str_replace('.', '', $extension));
		$object->setImage('sha512', sha512(file_get_contents($upfilepath)));
		$filename = 'object' . $object->getId() . '-' . $object->getImage('sha512') . '.' . $object->getImage('type');
		$filepath = __DIR__ . '/../../data/object/' . $filename;
		file_put_contents($filepath, file_get_contents($upfilepath));
		if (!file_exists($filepath)) {
			throw new \Exception(__('Impossible de sauvegarder l\'image', __FILE__));
		}
		$object->save();
		ajax::success(array('filepath' => $filepath));
	}

Idem dans jeedom.ajax.class aux ligne 600 et 601, ici cela permets d’utiliser des svg et des webp pour les widgets.

Si jamais…

3 « J'aime »

Pourquoi tu fais pas un PR sur Git ?

1 « J'aime »

Jamais fait sur le core, je regarderai comment cela se passe.

Traité par le PR add more img format · jeedom/core@3b0a2b8 · GitHub

Le sujet donc être fermé.

2 « J'aime »

Ce sujet a été automatiquement fermé après 24 heures suivant le dernier commentaire. Aucune réponse n’est permise dorénavant.