[RESOLU] Problème qualité d'image redimensionné ;-(

Petit nouveau ! | 8 Messages

29 mars 2015, 14:37

Bonjour à tous,

J'ai un composant Joomla qui est une galerie images mais les images sont compressé et c'est pas très jolie, j'ai cherché comment faire pour garder une bonne qualité mais je trouve PAS, dès fois je suis un peu une bêbete :oops:

le script est :

Code : Tout sélectionner

<?php /** **/ defined('_VALID_MOS') or die('Direct Access to this location is not allowed.'); class Config { var $_configFile = null; var $tabs = null; var $selectgallery = null; var $usertype = null; var $published = null; var $max_image_size = null; var $tmb_image_wd = null; var $tmb_image_hg = null; var $slaids_text = null; var $slaids_wait = null; var $slaids_duration = null; var $slaids_effect = null; var $slaids_transitions = null; var $slaids_direction = null; var $slaids_tmbcolumn = null; var $slaids_tmbrows = null; var $img_image_wd0 = null; var $img_image_hg0 = null; var $tmb_image_wd0 = null; var $tmb_image_hg0 = null; var $slaids_textPosTop = null; var $slaids_textPosLeft = null; var $slaids_textWrapPosTop = null; var $slaids_textWrapPosLeft = null; var $slaids_textWrapWidth = null; var $slaids_textWrapHeight = null; var $slaids_textWrapBorder = null; var $slaids_textWrapBackground = null; var $fe_columnAmount = null; var $smoothg_delay = null; var $smoothg_duration = null; var $smoothg_slideshow = null; var $smoothg_carousel = null; var $smoothg_infopane = null; var $smoothg_links = null; var $smoothg_slideinfo = null; var $smoothg_caropacity = null; var $smoothg_caropacitybig = null; var $smoothg_carheight = null; var $img_image_wd1 = null; var $img_image_hg1 = null; var $smoothg_tmbimgwd = null; var $smoothg_tmbimghg = null; var $smoothg_tmbimgspacing = null; function Config(){ global $mosConfig_absolute_path; $this->_configFile = $mosConfig_absolute_path."/administrator/components/com_expgallery/config.expgallery.php"; } function load() { require_once($this->_configFile); $this->selectgallery = $selectgallery; $this->usertype = $usertype; $this->published = $published; $this->max_image_size = $max_image_size; $this->tmb_image_wd = $tmb_image_wd; $this->tmb_image_hg = $tmb_image_hg; $this->slaids_text = $slaids_text; $this->slaids_wait = $slaids_wait; $this->slaids_duration = $slaids_duration; $this->slaids_effect = $slaids_effect; $this->slaids_transitions = $slaids_transitions; $this->slaids_direction = $slaids_direction; $this->slaids_tmbcolumn = $slaids_tmbcolumn; $this->slaids_tmbrows = $slaids_tmbrows; $this->img_image_wd0 = $img_image_wd0; $this->img_image_hg0 = $img_image_hg0; $this->tmb_image_wd0 = $tmb_image_wd0; $this->tmb_image_hg0 = $tmb_image_hg0; $this->slaids_textPosTop = $slaids_textPosTop; $this->slaids_textPosLeft = $slaids_textPosLeft; $this->slaids_textWrapPosTop = $slaids_textWrapPosTop; $this->slaids_textWrapPosLeft = $slaids_textWrapPosLeft; $this->slaids_textWrapWidth = $slaids_textWrapWidth; $this->slaids_textWrapHeight = $slaids_textWrapHeight; $this->slaids_textWrapBorder = $slaids_textWrapBorder; $this->slaids_textWrapBackground = $slaids_textWrapBackground; $this->fe_columnAmount = $fe_columnAmount; $this->smoothg_delay = $smoothg_delay; $this->smoothg_duration = $smoothg_duration; $this->smoothg_slideshow = $smoothg_slideshow; $this->smoothg_carousel = $smoothg_carousel; $this->smoothg_infopane = $smoothg_infopane; $this->smoothg_links = $smoothg_links; $this->smoothg_slideinfo = $smoothg_slideinfo; $this->smoothg_caropacity = $smoothg_caropacity; $this->smoothg_caropacitybig = $smoothg_caropacitybig; $this->smoothg_carheight = $smoothg_carheight; $this->img_image_wd1 = $img_image_wd1; $this->img_image_hg1 = $img_image_hg1; $this->smoothg_tmbimgwd = $smoothg_tmbimgwd; $this->smoothg_tmbimghg = $smoothg_tmbimghg; $this->smoothg_tmbimgspacing = $smoothg_tmbimgspacing; } function save($option) { @chmod ($this->_configFile, 0766); $permission = is_writable($this->_configFile); if (!$permission) { mosRedirect("index2.php?option=$option&act=settings", 'Config file not writeable!'); break; } $config = "<?php\n"; $config .= "\$selectgallery = '" . $_POST['selectgallery'] . "';\n"; $config .= "\$usertype = '" . $_POST['usertype'] . "';\n"; $config .= "\$published = '" . $_POST['published'] . "';\n"; $config .= "\$max_image_size = '" . $_POST['max_image_size'] . "';\n"; $config .= "\$tmb_image_wd = '" . $_POST['tmb_image_wd'] . "';\n"; $config .= "\$tmb_image_hg = '" . $_POST['tmb_image_hg'] . "';\n"; $config .= "\$slaids_text = '" . $_POST['slaids_text'] . "';\n"; $config .= "\$slaids_wait = '" . $_POST['slaids_wait'] . "';\n"; $config .= "\$slaids_duration = '" . $_POST['slaids_duration'] . "';\n"; $config .= "\$slaids_effect = '" . $_POST['slaids_effect'] . "';\n"; $config .= "\$slaids_transitions = '" . $_POST['slaids_transitions'] . "';\n"; $config .= "\$slaids_direction = '" . $_POST['slaids_direction'] . "';\n"; $config .= "\$slaids_tmbcolumn = '" . $_POST['slaids_tmbcolumn'] . "';\n"; $config .= "\$slaids_tmbrows = '" . $_POST['slaids_tmbrows'] . "';\n"; $config .= "\$img_image_wd0 = '" . $_POST['img_image_wd0'] . "';\n"; $config .= "\$img_image_hg0 = '" . $_POST['img_image_hg0'] . "';\n"; $config .= "\$tmb_image_wd0 = '" . $_POST['tmb_image_wd0'] . "';\n"; $config .= "\$tmb_image_hg0 = '" . $_POST['tmb_image_hg0'] . "';\n"; $config .= "\$slaids_textPosTop = '" . $_POST['slaids_textPosTop'] . "';\n"; $config .= "\$slaids_textPosLeft = '" . $_POST['slaids_textPosLeft'] . "';\n"; $config .= "\$slaids_textWrapPosTop = '" . $_POST['slaids_textWrapPosTop'] . "';\n"; $config .= "\$slaids_textWrapPosLeft = '" . $_POST['slaids_textWrapPosLeft'] . "';\n"; $config .= "\$slaids_textWrapWidth = '" . $_POST['slaids_textWrapWidth'] . "';\n"; $config .= "\$slaids_textWrapHeight = '" . $_POST['slaids_textWrapHeight'] . "';\n"; $config .= "\$slaids_textWrapBorder = '" . $_POST['slaids_textWrapBorder'] . "';\n"; $config .= "\$slaids_textWrapBackground = '" . $_POST['slaids_textWrapBackground'] . "';\n"; $config .= "\$fe_columnAmount = '" . $_POST['fe_columnAmount'] . "';\n"; $config .= "\$smoothg_delay = '" . $_POST['smoothg_delay'] . "';\n"; $config .= "\$smoothg_duration = '" . $_POST['smoothg_duration'] . "';\n"; $config .= "\$smoothg_slideshow = '" . $_POST['smoothg_slideshow'] . "';\n"; $config .= "\$smoothg_carousel = '" . $_POST['smoothg_carousel'] . "';\n"; $config .= "\$smoothg_infopane = '" . $_POST['smoothg_infopane'] . "';\n"; $config .= "\$smoothg_links = '" . $_POST['smoothg_links'] . "';\n"; $config .= "\$smoothg_slideinfo = '" . $_POST['smoothg_slideinfo'] . "';\n"; $config .= "\$smoothg_caropacity = '" . $_POST['smoothg_caropacity'] . "';\n"; $config .= "\$smoothg_caropacitybig = '" . $_POST['smoothg_caropacitybig'] . "';\n"; $config .= "\$smoothg_carheight = '" . $_POST['smoothg_carheight'] . "';\n"; $config .= "\$img_image_wd1 = '" . $_POST['img_image_wd1'] . "';\n"; $config .= "\$img_image_hg1 = '" . $_POST['img_image_hg1'] . "';\n"; $config .= "\$smoothg_tmbimgwd = '" . $_POST['smoothg_tmbimgwd'] . "';\n"; $config .= "\$smoothg_tmbimghg = '" . $_POST['smoothg_tmbimghg'] . "';\n"; $config .= "\$smoothg_tmbimgspacing = '" . $_POST['smoothg_tmbimgspacing'] . "';\n"; $config .= "?>\n"; if ($fp = fopen($this->_configFile, "w")) { fputs($fp, $config, strlen($config)); fclose ($fp); } mosRedirect("index2.php?option=$option&act=settings", 'Settings saved.'); } } // class end class expgalleryCategories extends mosDBTable { var $id = null; var $name = null; var $url_img = null; var $published = null; function expgalleryCategories(&$db){ $this->mosDBTable('#__expgallery_categories', 'id', $db); } } // class end class expgalleryAds extends mosDBTable { var $id = null; var $user_id = null; var $cat_id = null; var $name = null; var $description = null; var $date_crt = null; var $published = null; function expgalleryAds(&$db){ $this->mosDBTable('#__expgallery_ads', 'id', $db); } } // class end class expgalleryImg extends mosDBTable { var $id = null; var $ad_id = null; var $url_big = null; var $url_img = null; var $url_tmb = null; var $img_width = null; var $img_height = null; var $tmb_width = null; var $tmb_height = null; function expgalleryImg(&$db){ $this->mosDBTable('#__expgallery_img', 'id', $db); } } // class end class ImageOptions { function isAllowable(&$file, $keyname) { $allowable = array ('jpg', 'gif', 'png'); $extension = substr(trim($file[$keyname]["name"]), -3); foreach($allowable as $val) { if(strcasecmp($val, $extension) == 0) return(1); } return(0); } function resize($filename, $original, $newx, $newy, $resized, $mod=0) { $result = array(); if(strlen($filename)) { if($mod == 0) { $filename = substr($filename, 0, strlen($filename) - 4); $filename .= "_".mktime(); } if($mod == 1) { $filename = substr($filename, 0, strlen($filename) - 4); $filename .= "_".mktime()."_t"; } } $imagetype = array( 1 => '1', 2 => '2', 3 => '3'); list($orgWidth, $orgHeight, $type, $attr) = getimagesize($original); if($type == $imagetype[2]) { $backup = $resized."/".$filename.".jpg"; // NAME OF BACKUP copy ($original, $backup); // COPY SOURCE TO BACKUP $source = imagecreatefromjpeg($backup); // CREATE IMAGE IDENTIFIER $sourcex = imagesx($source); // GET WIDTH $sourcey = imagesy($source); // GET HEIGHT if($newy == 0) { if($sourcex > $newx) { $newy = round(($newx * $sourcey) / $sourcex); } else { $newx = $sourcex; $newy = $sourcey; } } $destination = imagecreatetruecolor($newx, $newy); // CREATE A NEW TRUE COLOR IMAGE unlink($backup); // DELETE BACKUP FILE if(!imagecopyresampled($destination, $source, 0, 0, 0, 0, $newx, $newy, $sourcex, $sourcey)) { imagedestroy($source); // FREE MEMORY FROM $source imagedestroy($destination); // FREE MEMORY FROM $destination return(0); // RETURN ERROR } else { imagedestroy($source); if(imagejpeg($destination, $resized."/".$filename.".jpg")) { // CREATE RESIZED IMAGE imagedestroy($destination); $result[0]["width"] = $newx; $result[0]["height"] = $newy; $result[0]["name"] = $filename.".jpg"; return($result); // RETURN SUCCESS } imagedestroy($destination); } return (0); } if($type == $imagetype[1]) { $backup = $resized."/".$filename.".gif"; // NAME OF BACKUP copy ($original, $backup); // COPY SOURCE TO BACKUP $source = imagecreatefromgif($backup); // CREATE IMAGE IDENTIFIER $sourcex = imagesx($source); // GET WIDTH $sourcey = imagesy($source); // GET HEIGHT if($newy == 0) { if($sourcex > $newx) { $newy = round(($newx * $sourcey) / $sourcex); } else { $newx = $sourcex; $newy = $sourcey; } } $destination = imagecreatetruecolor($newx, $newy); // CREATE A NEW TRUE COLOR IMAGE unlink($backup); // DELETE BACKUP FILE if(!imagecopyresampled($destination, $source, 0, 0, 0, 0, $newx, $newy, $sourcex, $sourcey)) { imagedestroy($source); // FREE MEMORY FROM $source imagedestroy($destination); // FREE MEMORY FROM $destination return(0); // RETURN ERROR } else { imagedestroy($source); if(imagegif($destination, $resized."/".$filename.".gif")) { // CREATE RESIZED IMAGE imagedestroy($destination); $result[0]["width"] = $newx; $result[0]["height"] = $newy; $result[0]["name"] = $filename.".gif"; return($result); // RETURN SUCCESS } imagedestroy($destination); } return (0); } if($type == $imagetype[3]) { $backup = $resized."/".$filename.".png"; // NAME OF BACKUP copy ($original, $backup); // COPY SOURCE TO BACKUP $source = imagecreatefrompng($backup); // CREATE IMAGE IDENTIFIER $sourcex = imagesx($source); // GET WIDTH $sourcey = imagesy($source); // GET HEIGHT if($newy == 0) { if($sourcex > $newx) { $newy = round(($newx * $sourcey) / $sourcex); } else { $newx = $sourcex; $newy = $sourcey; } } $destination = imagecreatetruecolor($newx, $newy); // CREATE A NEW TRUE COLOR IMAGE unlink($backup); // DELETE BACKUP FILE if(!imagecopyresampled($destination, $source, 0, 0, 0, 0, $newx, $newy, $sourcex, $sourcey)) { imagedestroy($source); // FREE MEMORY FROM $source imagedestroy($destination); // FREE MEMORY FROM $destination return(0); // RETURN ERROR } else { imagedestroy($source); if(imagepng($destination, $resized."/".$filename.".png")) { // CREATE RESIZED IMAGE imagedestroy($destination); $result[0]["width"] = $newx; $result[0]["height"] = $newy; $result[0]["name"] = $filename.".png"; return($result); // RETURN SUCCESS } imagedestroy($destination); } return (0); } return(0); } /** * GD2 lib */ function checkgd() { $tmp_dat = gd_info(); if(is_array($tmp_dat) && count($tmp_dat) > 3) { unset($tmp_dat); return (1); } return(0); } }// class end class pageSort { var $prev_row = null; var $prev_filter = null; var $filter_val = null; var $letterlinks = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; var $numberslink = "0-9"; function pageSort($prev_row, $prev_filter = null) { $this->prev_row = $prev_row; $this->prev_filter = $prev_filter; } function getListLetters() { $html = ""; $html .= "\t<table class=\"adminlist\">\r\n"; $html .= "\t<tr><td>\r\n"; $html .= $this->getLettersLinks(); $html .= "\t<input type=\"hidden\" name=\"sort_by\" value=\"".$this->prev_row."\" />\r\n"; $html .= "\t</td></tr>\r\n"; $html .= "\t</table>\r\n"; return ($html); } function getFilter() { $html = ""; $html .= "\t<table class=\"adminlist\">\r\n"; $html .= "\t<tr><td>\r\n"; $html .= $this->getFilterInput(); $html .= "\t</td></tr>\r\n"; $html .= "\t</table>\r\n"; return ($html); } function getLettersLinks() { $html = ""; $start_ch = "["; $end_ch = "]"; $separator_ch = "|"; $html .= "\t<span class=\"pagenav\">".$start_ch."</span>\r\n"; if($this->prev_row != $this->numberslink && is_numeric($this->prev_row)) { $this->prev_row = $this->numberslink; } if($this->prev_row == $this->numberslink) { $html .= "\t<span class=\"pagenav\">".$this->numberslink."</span>\r\n"; } else { $html .= "\t<a href=\"#number\" class=\"pagenav\" onClick=\"javascript: document.adminForm.sort_by.value='".$this->numberslink."'; document.adminForm.filter_by.value=''; document.adminForm.submit(); return false;\">".$this->numberslink."</a>\r\n"; } $tmp_str = $this->letterlinks; for($i = 0; $i < strlen($tmp_str); $i++) { if($tmp_str[$i] == $this->prev_row) { $html .= "\t<span class=\"pagenav\">".$separator_ch."</span>\r\n"; $html .= "\t<span class=\"pagenav\">".$tmp_str[$i]."</span>\r\n"; } else { $html .= "\t<span class=\"pagenav\">".$separator_ch."</span>\r\n"; $html .= "\t<a href=\"#".$tmp_str[$i]."\" class=\"pagenav\" onClick=\"javascript: document.adminForm.sort_by.value='".$tmp_str[$i]."'; document.adminForm.filter_by.value=''; document.adminForm.submit(); return false;\">".$tmp_str[$i]."</a>\r\n"; } } $html .= "\t<span class=\"pagenav\">".$separator_ch."</span>\r\n"; $html .= "\t<a href=\"#all\" class=\"pagenav\" onClick=\"javascript: document.adminForm.sort_by.value=''; document.adminForm.filter_by.value=''; document.adminForm.submit(); return false;\">...</a> ".$end_ch."\r\n"; return ($html); } function getFilterInput() { $html = "\t<span class=\"pagenav\"><b>Filter:</b> <input class=\"text_area\" type=\"text\" name=\"filter_by\" maxlength=\"20\" size=\"25\" value=\"".$this->prev_filter."\" /></span>\r\n"; return ($html); } }// end of class ?>
Je comprends vraiment pas merci pour votre aide

Petit nouveau ! | 8 Messages

29 mars 2015, 17:23

Arrrf je trouve pas la solution, j'ai essayé avec truecolor j'ai essayé avec ,100) rien à faire :-( help Me please

Petit nouveau ! | 8 Messages

29 mars 2015, 19:32

Peut-être avec $quality mais je sais pas où il faut le mettre, personne pour aider SVP

ViPHP
AB
ViPHP | 5818 Messages

30 mars 2015, 01:27

Salut,

J'ai pas regardé ton code mais peut-être que tu pars d'images de très grandes dimensions (plusieurs méga) pour obtenir au final des vignettes assez petites.
Dans ce cas, comme les redimensionnements en php sont d'une qualité un peu moindre qu'avec un logiciel photo, il est possible que tu observes une perte de qualité.

Il y a une classe d'upload et redimensionnement ici. Elle est fournie dans un dossier prêt à l'emploi de sorte qu'il ne te faudra que quelques minutes pour l'essayer. Ainsi tu pourras voir si les redimensionnements sont de la même qualité que ceux que tu obtiens. Si oui c'est que le problème est bien celui que je viens d'invoquer plus haut et dans ce cas la seule solution est de fournir des fichiers originaux de plus petites dimensions. Si non c'est que ta fonction n'est pas optimisée et dans ce cas on pourra penser à modifier ton code.

Petit nouveau ! | 8 Messages

30 mars 2015, 07:14

Salut Ab,

Merci de ta réponse, non le problème ne vient pas de là, il vient de la GD qui est par défaut à 80 pour les images redimensionnées, c'est dans mon code qu'il faut changer quelques chose, mais je n'y arrive pas. :-)

Avatar du membre
Administrateur PHPfrance
Administrateur PHPfrance | 9782 Messages

30 mars 2015, 08:55

Bonjour,

Tu peux spécifier la qualité en paramètre de la fonction imagejpeg()
if(imagejpeg($destination, $resized."/".$filename.".jpg", null, 90)) { // CREATE RESIZED IMAGE
Ici j'ai mis 90 qui est habituellement largement suffisant, tu peux augmenter jusqu'à 100.
Quand tout le reste a échoué, lisez le mode d'emploi...

Petit nouveau ! | 8 Messages

30 mars 2015, 09:44

Bonjour @thur,

Merci je vais tester, et je te tiens au courant, en espérant que ça marche :priere:

Merci en tout cas d'avoir pris le temps de m'aider :D

Petit nouveau ! | 8 Messages

30 mars 2015, 09:55

Woowwwwwwwwwww @rthur un grand MERCI ça marche, et dire que j'ai passé un mauvais dimanche à cause de ça et la ça marche avec une zolie qualité.

MERCI

Petit nouveau ! | 8 Messages

30 mars 2015, 10:00

Oops voilà le BON code si ça peut aider quelqu'un : if(imagejpeg($destination, $resized."/".$filename.".jpg", 100))

avec null, y'a des petits défaut sur l'image.

Merci problème résolu

Avatar du membre
Administrateur PHPfrance
Administrateur PHPfrance | 9782 Messages

30 mars 2015, 10:57

Je te recommande de faire des tests avec des valeurs inférieures à 100 pour voir à partir de quel niveau de qualité ça reste acceptable car avec un niveau à 100 tes images vont être assez lourde en poids et donc longue à afficher pour ceux qui ont une connexion internet peu rapide.
Quand tout le reste a échoué, lisez le mode d'emploi...

Petit nouveau ! | 8 Messages

30 mars 2015, 11:47

Ok @rthur je vais voir en tout super MERCI encore de m'avoir aidé sur ce petit script là je suis trop contente que ça marche ;-)

Petit nouveau ! | 1 Messages

31 mars 2015, 06:04

J'avoue que j'ai pas compris ce que tu as dit...

ViPHP
AB
ViPHP | 5818 Messages

31 mars 2015, 06:29

Salut,

@rthur te conseille une valeur de 90 et de mon côté dans la classe de redimensionnement j'ai mis par défaut 88, seuil au delà duquel je ne voyais plus d'amélioration de la qualité après de très nombreux essais. Pour dire qu'on à une perception très voisine du maximum utile.
En fait c'est important que tu ne mette pas 100 car la différence d'une dizaine de pourcent est assez considérable au niveau du poids (pour ne rien gagner au niveau de la qualité). Et pour peu que tu affiche plusieurs images la différence pour le chargement de ta page sera sensible avec des connexion moyennes (bornes wifi par exemple).
Je te refais donc la même recommandation qu'@rthur d'autant plus que google commence à prendre en considération la vitesse de chargement des pages pour son classement...

Après si tu veux vraiment le top qualité, mettre à 100 ne sert à rien. Il faut faire le redimensionnement dans un logiciel photo (même un gratuit comme photofiltre) car ils possèdent un système de renforcement des contours lors des redimensionnements que ne possède pas la bibliothèque GD, sans doute pour soulager le serveur. C'est assez visible avec les très forts coefficients de redimensionnement. Cela dit tant qu'il ne s'agit pas d'afficher une galerie photo pour un photographe exigeant, on peut se contenter de la bibliothèque GD qui fait assez bien son travail.