Qui a déjà installé DFGallery 2.005 sur 000webhost ??

Statut
La discussion n'est pas ouverte à d'autres réponses

ORiGaMi

<b>HANDICAP LSF</b>
hello, à tous et à NEOIII,

il s'agit de DFGalery v2.005 si quelqu'un s'y connaisse.
la source gallery : http://www.dezinerfolio.com/dfgallery-2/free-flash-gallery?page=22
Voici mon lien : http://constr.comule.com/gallery/

j'ai cette erreur:
Invalid cURL response.
We expected 'true' from the url :
http://constr.comule.com/gallery/index.php/api/rest/test_curl

Depuis 3 jours, j'ai fait plusieur test pour résoudre le probléme d'un lien de curl response que l'on voit sur mon site, j'ai pourtant fait éditer la page install.php + config.php en esperant que je pourrai enfin installer la gallerie mais elles m'ont semblé aucune problématique d'où http://constr.comule.com/gallery/install.php.

j'ai aussi lu les multiples reponses (provenant du site officielle dezinerfolio) qui ont eu le meme probléme que moi, j'ai meme essayé de tester si je suis bien en php5 de chez 000webhost ainsi json/curl activé.

je ne vois pas d'autre incohérence qui m'empeche d'installer la gallerie, j'ai édité plusieur fois sur un fichier .hatccess avec différent test, sans succés,

voici le script :
<filesmatch ?\.(engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template)$?="">
FilesMatch "\.(engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template)$">
Order allow,deny
/FilesMatch>
Options -Indexes
Options +FollowSymLinks
ErrorDocument 404 /index.php
DirectoryIndex index.php
IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /gallery
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
/IfModule>
</filesmatch><ifmodule mod_rewrite.c=""></ifmodule>

la reponse rewrite http://constr.comule.com/test/rewrite.php?link2.html

des info:
http://codeigniter.com/user_guide/general/urls.html
http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html

si vous avez des questions, je répond lorsqu'on fait étape par étape car j'ai fait 3jours de recherche en pensant même si je resoudrai tout seul donc j'ai besoin de votre aide :)

si besoin de savoir plus, voici : http://constr.comule.com/test/apacherewrite.php

D'avance merci !!
 
Dernière édition:
Salut,

Je ne peux pas accéder à ton site pour le moment (bloqué au taf par le proxy), mais essaye ce .htaccess :

Code:
Order allow,deny

Options -Indexes
Options +FollowSymLinks
ErrorDocument 404 /index.php
DirectoryIndex /index.php

RewriteEngine on
#RewriteBase /gallery
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /gallery/index.php?$1 [L]
 
Dernière édition:
désolé je suis entrain de corriger, là tu es accessible.

http://constr.comule.com/gallery/index.php/api/rest/test_curl elle me dit true alors qu'il y a toujours Invalid cURL response.

je vais essayer avec ton htaccess

EDIT 13h16:
FilesMatch "\.(engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template)$">
Order allow,deny
/FilesMatch>Options -Indexes
Options +FollowSymLinks
ErrorDocument 404 /index.php
DirectoryIndex index.php
IfModule mod_rewrite.c>
RewriteEngine on
#RewriteBase /gallery
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /gallery/index.php?$1 [L]
/IfModule>
<ifmodule mod_rewrite.c=""></ifmodule>

Encore Invalid cURL response.

edit 13h23:
FilesMatch "\.(engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template)$">
Order allow,deny
/FilesMatch>Options -Indexes
Options +FollowSymLinks
ErrorDocument 404 /index.php
DirectoryIndex /index.php
IfModule mod_rewrite.c>
RewriteEngine on
#RewriteBase /gallery
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /gallery/index.php?$1 [L]
/IfModule>
<ifmodule mod_rewrite.c=""></ifmodule>

avec "/", elle envoie l'index de gallerie hors ligne
 
Dernière édition:
Comme dit plus haut, je suis au taf, et le proxy m'empêche d'aller sur ton site. Je regarderai donc ça plus en profondeur ce soir :sourire116-287e:
 
effectivement, je la laisse tel qu'elle est, à ce soir :)

edit:
il me semble que Apache's Mod Rewrite qui n'est pas sur le serveur, je ne sais pas :(
 
Dernière édition:
Le mod_rewrite est bien activé, ce n'est pas la cause du problème :icon_wink-221e:

En fait, cela vient de ce fichier : http://constr.comule.com/gallery/index.php/api/rest/test_curl Il est censé renvoyer true, mais 000webhost ajoute un système de statistiques à la fin de chaque fichiers, donc ici true devient
HTML:
true
<!-- Hosting24 Analytics Code -->
<script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>
<!-- End Of Analytics Code -->
et donc l'installateur de dfGallery ne le reconnait pas...

Après, pour corriger ce problème, c'est une autre paire de manches...

Le top serait de bypasser cette vérification.

Dans le fichier /gallery/index.php, tu dois avoir ce code à un moment :

PHP:
// CLEAN URLS.
if(extension_loaded('curl')){
$curl_url = 'http://'.$_SERVER['SERVER_NAME'].substr($_SERVER['SCRIPT_NAME'],0,strpos($_SERVER['SCRIPT_NAME'],'/index.php')). '/api/rest/test_curl';
$clean_url_check = curl_init($curl_url);
curl_setopt($clean_url_check,CURLOPT_RETURNTRANSFER,true);
$clean_url_check_resp = curl_exec($clean_url_check);
if (curl_errno($clean_url_check)>0){
$checks[] = array('A curl error occured while checking for clean urls.',false,"URL : $curl_url
cURL message : ". curl_error($clean_url_check));
}else{
if($clean_url_check_resp == 'true'){
$checks[] = array('Clean urls\' have been enabled.',true,'');
}else{
$checks[] = array('Invalid cURL response.',false,"We expected 'true' from the url : $curl_url");
}
}
}else{
$checks[] = array('Unable to check clean urls, as curl is disabled.',false,'Please enable cURL extension first.');
}

Il faudrait le modifier ainsi :

PHP:
// CLEAN URLS.
if(extension_loaded('curl')){
$curl_url = 'http://'.$_SERVER['SERVER_NAME'].substr($_SERVER['SCRIPT_NAME'],0,strpos($_SERVER['SCRIPT_NAME'],'/index.php')). '/api/rest/test_curl';
$clean_url_check = curl_init($curl_url);
curl_setopt($clean_url_check,CURLOPT_RETURNTRANSFER,true);
$clean_url_check_resp = curl_exec($clean_url_check);
if (curl_errno($clean_url_check)>0){
$checks[] = array('A curl error occured while checking for clean urls.',false,"URL : $curl_url
cURL message : ". curl_error($clean_url_check));
}else{
if($clean_url_check_resp == 'true' || 1 == 1){
$checks[] = array('Clean urls\' have been enabled.',true,'');
}else{
$checks[] = array('Invalid cURL response.',false,"We expected 'true' from the url : $curl_url");
}
}
}else{
$checks[] = array('Unable to check clean urls, as curl is disabled.',false,'Please enable cURL extension first.');
}
 
mod_write, je sais bien qu'elle est activé et c'est bien cela qui me demande de croire que Curl ne la reconnait pas.

le code a modifié est bien celui de /gallery/install.php, pas celui de index.php ;)

alors j'ai fait exactement comme tu as dit :

if($clean_url_check_resp == 'true' modifier to if($clean_url_check_resp == 'true' || 1 == 1){

http://constr.comule.com/gallery/index.php = probléme cette page index.php du à ton code et en enlevant || 1 == 1),l'index.php remarche.
http://constr.comule.com/gallery/index.php/admin/login = hourra, grace à ton code, j'obtiens une fenetre user/password
http://constr.comule.com/gallery/install.php = comme elle prouve.


EDIT1:

yes, j'ai trouvé, j'ai corrigé à nouveau .htaccess, elle est enfin resolu. merci à NEOIII car sans lui je continuerai à perdre des heures, houuurraa



EDIT 23h20:
http://constr.comule.com/gallery/ = NICKEL, j'ai crée la base de donnée, ensuite j'ai crée 1 album et sous album puis probléme d'upload d'image avec une espece fakepath et ca n'a pas pu passer lors de transfert.
http://constr.comule.com/gallery/install.php = config.php m'a semblé correct, encore à résoudre :(, probléme du au code app_path: config/config.php >> code à corriger?

que peut-on procéder en 1er ? rajouter nouvelle ligne (concernant upload image?) dans htaccess ?
 
Dernière édition:
Concernant l'upload d'images, j'ai pas tout saisi.

Pour la suite, tu peux poster le .htaccess que tu as maintenant ?
 
hello,

d'accord, voici le fichier htaccess :
PHP:
  Order allow,deny

 
Options -Indexes
Options +FollowSymLinks
 
ErrorDocument 404 /index.php
DirectoryIndex index.php
 
RewriteEngine On
 RewriteBase /gallery
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond $1 !^(index\.php|robots\.txt|scripts)
 RewriteRule ^(.*)$ index.php/$1 [L]

et pour l'upload d'image:
voici le screen :problemupload.png là, lors de transfert de plusieur minutes, elle tourne vraiment en boucle et ca n'a jamais passé dans le dossier de l'album


EDIT 16/06:
j'ai beau retester d'uploader des images, je ne parviens pas vraiment. ca ne m'avance pas trop, pour l'instant, dans mon nouveau site/design :(
 
Dernière édition:
finalement, avec un rude petit épreuve, je ne pouvais que penser s'il fallait creer la page index.html à côté d'un dossier Gallery qui contient un index.php (uniquement pour l'admin).
En créant index.html avec une insertation code flash pour pouvoir le lire. je suis satisfait, voir http://constr.comule.com/index.html

concernant le probléme d'upload d'image, ca vient en cause de mon explorateur internet explorer. Dans le doute, j'ai fait passer sous chrome et avoir
réussi à transferer la photo.

Où dois-je rajouter la fonctionnalité pour comptabiliser internet explorer???
 
Dernière édition:
Internet Explorer à la fâcheuse habitude de ne pas respecter les standards (même s'il s'est amélioré avec les dernières versions). Si cela ne fonctionne pas avec IE mais que cela fonctionne avec Chrome, utilises Chrome :icon_wink-221e:
 
merci de ta conclusion,
Pour ma part, je suis plutot d'accord avec toi concernant IE :hein-2f49:

avant de mettre mon post en prefixe RESOLU:
est ce que tu connais un script ou sais tu creer un script comme celui-là: http://www.davepellegrin.com/ c'est ce script en cliquant sur le lien about ou lien client ou lien contact tout en gardant la barre de menu.
elle m'interesse ce script, j'aimerai l'ajouter dans mon site.

c'est la derniere chose que je veux :icon17-36f7:
 
Dernière édition:
merci,

j'ai regardé pas mal de truc de ces javascript, ca ressemble presque à http://www.davepellegrin.com/ et manque la fonction de cacher la page lorsque le menu reste en haut de la fenetre. sinon j'ai pris un script pour voir.
j'espere retrouver semblable via mon ami google " recherche JS anchor slide/jQuerry :)
 
j'ai contacté le site, le webmaster davepellerin est sympa, voici ce qu'il m'a repondu :

Hi Toto,
It's a mix of CSS styling, JavaScript and jQuery effects. I can't
remember which example I followed on jQuery's website but do a google search for
"persistent jQuery menu" and you should be able to find something similar.

Cheers

je vais essayer cela cet apres midi :) et merci encore :)
 
Dernière édition:
tu peux donc aller voir mon site, j'ai edité le script pour que le barre de menu dont le longueur est de 750px doit etre 100%, good.
il me manque 3 derniere chose,

La premiere:
voir le site de dave pellegrin, en cliquant CONTACT, elle se defile vers la partie contact et il y a une seconde barre apparait en bas.
j'ouvre le script :
PHP:
$(function(){
 
 var menu = $('#menu'),
  pos = menu.offset();
  
  $(window).scroll(function(){
   if($(this).scrollTop() > pos.top+menu.height() && menu.hasClass('default')){
    menu.fadeOut('fast', function(){
     $(this).removeClass('default').addClass('fixed').fadeIn('fast');
    });
   } else if($(this).scrollTop() <= pos.top && menu.hasClass('fixed')){
    menu.fadeOut('fast', function(){
     $(this).removeClass('fixed').addClass('default').fadeIn('fast');
    });
   }
  });
});

je dois rajouter $(this)***********pos.low (creation d'une barre en bas), tu peux me le coder stp ? afin de reproceder plus tard par moi-même.

La deuxieme:
en cliquant le lien clients, (chez davepellerin), cette page clients est caché puis apparait lors de cliquage lien clients

la troisieme:
j'ai edité plusieur fois le css d'une barre des menu, reordrer verticalement la barre de menu lors de defilement de ma page, j'ai mis [ center ] [/ center ]donc elle n'est pas abouti que je voulais.
le script :
PHP:
body {
 background: #efefef;
 margin: 0;
 padding: 0;
 border: none;
 text-align: center;
 font: normal 13px Verdana, sans-serif;
 color: #222;
}
#navi {
 height: 50px;
 margin-top: 50px;
}
#menu {
 background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #426d9c), color-stop(40%, #0f67a1), color-stop(100%, #1384d1));
 background: -moz-linear-gradient(top, #426d9c, #0f67a1, #1384d1);
 
 border-radius: 5px;
 -webkit-border-radius: 5px;
 -moz-border-radius: 5px;
 
 line-height: 50px;
 text-align: center;
 margin: 0 auto;
 padding: 0;
}
#content {
 width: 750px;
 margin: 0 auto;
 margin-bottom: 25px;
 padding: 30px 0;
 text-align: left;
}
ul {
 padding: 0;
}
ul li {
 list-style-type: none;
 display: inline;
 margin-right: 15px;
}
ul li a {
 color: #fff;
 text-decoration: none;
 text-shadow: 1px 1px 1px #000;
 padding: 3px 7px;
 
 border-radius: 5px;
 -webkit-border-radius: 5px;
 -moz-border-radius: 5px;
 
 -webkit-transition-property: color, background;
 -webkit-transition-duration: 0.5s, 0.5s;
}
ul li a:hover {
 background: #01458e;
 color: #ff0;
 -webkit-transition-property: color, background;
 -webkit-transition-duration: 0.5s, 0.5s;
}
.default {
 width: 100%;
 height: 50px;
 
 box-shadow: 0 5px 20px #888;
 -webkit-box-shadow: 0 5px 20px #888;
 -moz-box-shadow: 0 5px 20px #888;
}
.fixed {
 position: fixed;
 top: -5px;
 left: 0;
 width: 100%;
 
 box-shadow: 0 0 40px #222;
 -webkit-box-shadow: 0 0 40px #222;
 -moz-box-shadow: 0 0 40px #222;
}

D'avance, merci :)

ps: ensuite une fois terminé, je close mon topic verrouillé
 
Dernière édition:
Salut,

1. Essaye ça :dontknow-102c:

Code:
$(function(){
 
 var menu = $('#menu');
 var footer = $('#footer');
  pos = menu.offset();
  fpos = footer.offsset();
  
  $(window).scroll(function(){
   if($(this).scrollTop() > pos.top+menu.height() && menu.hasClass('default')){
    menu.fadeOut('fast', function(){
     $(this).removeClass('default').addClass('fixed').fadeIn('fast');
    });
    footer.fadeOut('fast', function(){
     $(this).removeClass('default').addClass('fixed').fadeIn('fast');
    });
   } else if($(this).scrollTop() <= pos.top && menu.hasClass('fixed')){
    menu.fadeOut('fast', function(){
     $(this).removeClass('fixed').addClass('default').fadeIn('fast');
    });
    footer.fadeOut('fast', function(){
     $(this).removeClass('fixed').addClass('default').fadeIn('fast');
    });
   }
  });
});

Avec ta barre du bas ayant l'id footer et la même construction que la barre menu, mais positionnée en bas).

2. C'est là aussi un fader. A priori, cela devrait fonctionner en mettant le bloc contact à 0% d'opacité (comme le menu et le footer) :

HTML:
<a href='#ancre_du_contact' onclick="$('#contact').fadeOut('fast', function(){$(this).removeClass('fixed').addClass('default').fadeIn('fast');});">Texte de l'ancre</a>

3. Pas compris :dontknow-102c:
 
1.
Code:
[COLOR=#008000]<[/COLOR]$(function(){
 
 var menu = $('#menu');
 var footer = $('#footer');
  pos = menu.offset();
  fpos = footer.offsset();
  
  $(window).scroll(function(){
   if($(this).scrollTop() > pos.top+menu.height() && menu.hasClass('default')){
    menu.fadeOut('fast', function(){
     $(this).removeClass('default').addClass('fixed').fadeIn('fast');
    });
    footer.fadeOut('fast', function(){
     $(this).removeClass('default').addClass('fixed').fadeIn('fast');
    });
   } else if($(this).scrollTop() <= pos.top && menu.hasClass('fixed')){
    menu.fadeOut('fast', function(){
     $(this).removeClass('fixed').addClass('default').fadeIn('fast');
    });
    footer.fadeOut('fast', function(){
     $(this).removeClass('fixed').addClass('default').fadeIn('fast');
    });
   }
  });
});
j'ai fait et ca a tout enlevé le barre du menu


2.
HTML:
<a href='#ancre_du_contact' onclick="$('#contact').fadeOut('fast', function(){$(this).removeClass('fixed').addClass('default').fadeIn('fast');});">Texte de l'ancre</a>


je crois que j'ai placé en erreur >>> j'ai fait ceci:
PHP:
     <       li>< a  h r e f ="#TEST" r e l ="" id="TEST" class="anchorLink">TEST</ a ></ l i >

.....
....
......
< a h r e f ='#TEST' onclick="$('#TEST').fadeOut('fast', function(){$(this).removeClass('fixed').addClass('default').fadeIn('fast');});">TEST
voir le site (le mien)
 
Dernière édition:
1.
PHP:
  <div id="footer" class="default">
   <ul>
   <li><a href="#TEST" rel="" id="anchor" class="anchorLink">TEST</a></li>
    </ul>
  </div>
voici id footer, je l'ai placé tout en bas de la page html

2. je reformule: ca ne marche pas si j'ai mal placé dans cet endroit ? j'ai essayé ce code dans le menu, non plus. J'ai même essayé avec vice versa.

je reessaye !!
 
Dernière édition:
Bonjour,
commençons par le commencement, un bonjour, un salut, un hello au début et un merci à la fin, la politesse ne fait pas de mal bien au contraire :)
ensuite, peux tu nous dire ce que tu veux, ce que tu cherches, quel est le problème ?! bref être un peu plus explicite, car là ce n'est pas évident
néanmoins je te souhaite de passer une bonne journée :)
 
Dernière édition:
Salut,
faut-il toujours redire "salut" et "merci" a chaque message?

Le probléme doit venir de moi en re-apprentissage du language code et qu'un simple aide rapide (de formidable NEoIII) pour pouvoir m'avancer dans la construction de mon site, j'ai réussi quelque détails mais pas forcémenent fini mais elle est presque fini.

je suppose que je peux fermer mon topic :)

D'avance merci :icon_wink-221e:
 
Dernière édition:
Salut,

Juste un p'tit retour d'info à propos de ce sujet "We expected 'true' from the url:"

Depuis plusieurs jours je galère avec ce script, qui fonctionnait parfaitement sous PHP 5.2 & depuis le passage à PHP 5.3, plus RIEN !!!

J'avais effectué toutes les manifs données par notre chère NEOIII dans ce topic & aucune ne fonctionnait pour ma part...

Puis.... je viens de tomber sur ce post (en direct du forum officiel du script posté par un certain "rafaelspfonseca" le 19/03/2012) :

====================SOLUÇÃO=======================
Depois de horas de pesquisas e testes, consegui juntar algumas dicas e consegui
fazer a galeria voltar a funcionar em um servidor no qual já estava instalado e
consegui instalar e outro (ambos com PHP 5.3)
Segue os aquivos que precisei alterar: (instalado na pasta /gallery)
root/lib/ci/libraries/Loader.php
-----------------------------------------------------------------------------------
----------------
at line 249 replaced =& to = since operator =& is deprecated and now you can use =
instead
$CI->dbutil =& new $class();
with
$CI->dbutil = new $class();
- probably the best thing would be to simple replace all =& with = did that and so
far it works...
====================================
root/lib/ci/libraries/URI.php
------------------------------------------------------
at line 190 replaced command:
if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+
$|i", $str))
with
if ( ! preg_match("|^[".($this->config->item('permitted_uri_chars'))."]+$|i",
rawurlencode($str)))
====================================
root/lib/ci/codeigniter/CodeIgniter.php
------------------------------------------------------
at line 60 replaced command
set_magic_quotes_runtime(0); // Kill magic quotes
with
ini_set('magic_quotes_runtime', 0);
====================================
root/lib/ci/codeigniter/Common.php
------------------------------------------------------
at line 123 replaced command
$objects[$class] =& new $name();
with
$objects[$class] = new $name();
at line 129 replaced command
$objects[$class] =& new $name();
with
$objects[$class] = new $name();
====================================
root/lib/ci/database/DB.php
------------------------------------------------------
at line 133 replaced command
$DB =& new $driver($params);
with
$DB = new $driver($params);
====================================
root/app/config/config.php
------------------------------------------------------
at line 129 replaced command:
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
with:
$config['permitted_uri_chars'] = 'a-z 0-9~%\.\:_\-';

En suivant les instructions à la lettre, j'ai réussi à réinstaller le script ! (il y a encore quelques erreurs mineures comme l'importation des images via le FTP mais le tout a l'air de bien tourner...).

Question pour Mr Fox! Tout est correct dans les codes donnés plus haut ? :confused-188a:

:hat-1194:
 
c'est basé sur le framework codeigniter ?
j'en ai ch!é pour faire un projet avec ça, je préfère de loin faire mes scripts en manuel,
en tout cas ça m'a l'ai bon pour le remplacement de =& par = vu que =& n'est plus supporté (obsolète) d'après ses dires :)
 
Oui, je crois que tu as tout dit mon GlouGlou.

Quand tu auras un très long moment de libre..., essaie de jeter un oeil au code source et si possible le rendre 100% compatible PHP 5.3 voire 5.4 :panic:

:icon-biglaugh-2218:
 
ok, je vais essayer de me faire une machine virtuelle demain (plus tard) et d'ici Dimanche je vais trouver le courage (et le temps) pour tripoter un peu sur 5.2 puis 5.4 ;)
 
Wow! t'as vraiment du temps à perdre mon GlouGlou :laughing-11ed::laughing-11ed::laughing-11ed: Actuellement, j'ai PHP 5.3.19 sur le serveur Web pour info :sourire116-287e:

Au passage, désolé d'avoir squatté ton topic "ORiGaMi" - je pense qu'il est intéressant de regrouper toutes les infos & erreurs concernant ce script ici, cela pourrait servir à d'autres plus tard...

Voici l'erreur donnée plus haut :

A PHP Error was encountered
Severity: 8192
Message: Function eregi() is deprecated
Filename: libraries/Image_lib.php
Line Number: 353


qH-ZUeu9au5UOSWs-IO1BMDAlg99_Ri4UpJMeZKqnjCjK1PN2hQL8ITwBxNgmWbxQUFgceBAV-HSHYg6pgM2nP1hl6RX3k0GUpE3VKX0ydvF2DVdreAkZifS9dI

Code:
if (eregi("gd2$", $protocol))
TMvu1ispJABQb3MmRJzZAcxlU70Mll987pi4QSvpTkX1djByRI8k8ivTDjpn4IMgIPpJdONo-Rf5axmwPTRp3u3815BpOJ-IWaQtDtHW0CikAg2j6jUVuHfnuw0


Code source de la page Image_lib.php

PHP:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * CodeIgniter
 *
 * An open source application development framework for PHP 4.3.2 or newer
 *
 * @package		CodeIgniter
 * @author		ExpressionEngine Dev Team
 * @copyright	Copyright (c) 2006, EllisLab, Inc.
 * @license		http://codeigniter.com/user_guide/license.html
 * @link		http://codeigniter.com
 * @since		Version 1.0
 * @filesource
 */

// ------------------------------------------------------------------------

/**
 * Image Manipulation class
 *
 * @package		CodeIgniter
 * @subpackage	Libraries
 * @category	Image_lib
 * @author		ExpressionEngine Dev Team
 * @link		http://codeigniter.com/user_guide/libraries/image_lib.html
 */
class CI_Image_lib {
	
	var $image_library		= 'gd2';  	// Can be:  imagemagick, netpbm, gd, gd2
	var $library_path		= '';
	var $dynamic_output		= FALSE;	// Whether to send to browser or write to disk
	var $source_image		= '';	
	var $new_image			= '';
	var $width				= '';
	var $height				= '';
	var $quality			= '90';
	var $create_thumb		= FALSE;
	var $thumb_marker		= '_thumb';
	var $maintain_ratio		= TRUE;  	// Whether to maintain aspect ratio when resizing or use hard values
	var $master_dim			= 'auto';	// auto, height, or width.  Determines what to use as the master dimension
	var $rotation_angle		= '';
	var $x_axis				= '';
	var	$y_axis				= '';
	
	// Watermark Vars
	var $wm_text			= '';			// Watermark text if graphic is not used
	var $wm_type			= 'text';		// Type of watermarking.  Options:  text/overlay
	var $wm_x_transp		= 4;
	var $wm_y_transp		= 4;
	var $wm_overlay_path	= '';			// Watermark image path
	var $wm_font_path		= '';			// TT font
	var $wm_font_size		= 17;			// Font size (different versions of GD will either use points or pixels)
	var $wm_vrt_alignment	= 'B';			// Vertical alignment:   T M B
	var $wm_hor_alignment	= 'C';			// Horizontal alignment: L R C
	var $wm_padding			= 0;			// Padding around text
	var $wm_hor_offset		= 0;			// Lets you push text to the right
	var $wm_vrt_offset		= 0;			 // Lets you push  text down
	var $wm_font_color		= '#ffffff';	// Text color
	var $wm_shadow_color	= '';			// Dropshadow color
	var $wm_shadow_distance	= 2;			// Dropshadow distance
	var $wm_opacity			= 50; 			// Image opacity: 1 - 100  Only works with image
	
	// Private Vars
	var $source_folder		= '';
	var $dest_folder		= '';
	var $mime_type			= '';
	var $orig_width			= '';
	var $orig_height		= '';
	var $image_type			= '';
	var $size_str			= '';
	var $full_src_path		= '';
	var $full_dst_path		= '';
	var $create_fnc			= 'imagecreatetruecolor';
	var $copy_fnc			= 'imagecopyresampled';
	var $error_msg			= array();
	var $wm_use_drop_shadow	= FALSE;
	var $wm_use_truetype	= FALSE;		
	
	/**
	 * Constructor
	 *
	 * @access	public
	 * @param	string
	 * @return	void
	 */	
	function CI_Image_lib($props = array())
	{
		if (count($props) > 0)
		{
			$this->initialize($props);
		}
		
		log_message('debug', "Image Lib Class Initialized");
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Initialize image properties
	 *
	 * Resets values in case this class is used in a loop
	 *
	 * @access	public
	 * @return	void
	 */	
	function clear()
	{
		$props = array('source_folder', 'dest_folder', 'source_image', 'full_src_path', 'full_dst_path', 'new_image', 'image_type', 'size_str', 'quality', 'orig_width', 'orig_height', 'rotation_angle', 'x_axis', 'y_axis', 'create_fnc', 'copy_fnc', 'wm_overlay_path', 'wm_use_truetype', 'dynamic_output', 'wm_font_size', 'wm_text', 'wm_vrt_alignment', 'wm_hor_alignment', 'wm_padding', 'wm_hor_offset', 'wm_vrt_offset', 'wm_font_color', 'wm_use_drop_shadow', 'wm_shadow_color', 'wm_shadow_distance', 'wm_opacity');
	
		foreach ($props as $val)
		{
			$this->$val = '';
		}

		// special consideration for master_dim
		$this->master_dim = 'auto';
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * initialize image preferences
	 *
	 * @access	public
	 * @param	array
	 * @return	void
	 */	
	function initialize($props = array())
	{
		/*
		 * Convert array elements into class variables
		 */
		if (count($props) > 0)
		{
			foreach ($props as $key => $val)
			{
				$this->$key = $val;
			}
		}

		/*
		 * Is there a source image?
		 *
		 * If not, there's no reason to continue
		 *
		 */
		if ($this->source_image == '')
		{
			$this->set_error('imglib_source_image_required');
			return FALSE;	   	
		}
		
		/*
		 * Is getimagesize() Available?
		 *
		 * We use it to determine the image properties (width/height).
		 * Note:  We need to figure out how to determine image
		 * properties using ImageMagick and NetPBM
		 *
		 */		
		if ( ! function_exists('getimagesize'))
		{
			$this->set_error('imglib_gd_required_for_props');
			return FALSE;		
		}
		
		$this->image_library = strtolower($this->image_library);
		
		/*
		 * Set the full server path
		 *
		 * The source image may or may not contain a path.
		 * Either way, we'll try use realpath to generate the
		 * full server path in order to more reliably read it.
		 *
		 */	
		if (function_exists('realpath') AND @realpath($this->source_image) !== FALSE)
		{
			$full_source_path = str_replace("\\", "/", realpath($this->source_image));
		}
		else
		{
			$full_source_path = $this->source_image;
		}
		
		$x = explode('/', $full_source_path);
		$this->source_image = end($x);
		$this->source_folder = str_replace($this->source_image, '', $full_source_path);
								
		// Set the Image Properties
		if ( ! $this->get_image_properties($this->source_folder.$this->source_image))
		{
			return FALSE;	   	
		}				

		/*
		 * Assign the "new" image name/path
		 *
		 * If the user has set a "new_image" name it means
		 * we are making a copy of the source image. If not
		 * it means we are altering the original.  We'll
		 * set the destination filename and path accordingly.
		 *
		 */			
		if ($this->new_image == '')
		{
			$this->dest_image = $this->source_image;
			$this->dest_folder = $this->source_folder;
		}
		else
		{
			if (strpos($this->new_image, '/') === FALSE)
			{
				$this->dest_folder = $this->source_folder;
				$this->dest_image = $this->new_image;
			}
			else
			{
				if (function_exists('realpath') AND @realpath($this->new_image) !== FALSE)
				{
					$full_dest_path = str_replace("\\", "/", realpath($this->new_image));
				}
				else
				{
					$full_dest_path = $this->new_image;
				}
				
				// Is there a file name?
				if ( ! preg_match("#\.(jpg|jpeg|gif|png)$#i", $full_dest_path))
				{
					$this->dest_folder = $full_dest_path.'/';
					$this->dest_image = $this->source_image;
				}
				else
				{
					$x = explode('/', $full_dest_path);
					$this->dest_image = end($x);
					$this->dest_folder = str_replace($this->dest_image, '', $full_dest_path);
				}
			}
		}

		/*
		 * Compile the finalized filenames/paths
		 *
		 * We'll create two master strings containing the
		 * full server path to the source image and the
		 * full server path to the destination image.
		 * We'll also split the destination image name
		 * so we can insert the thumbnail marker if needed.
		 *
		 */	
		if ($this->create_thumb === FALSE OR $this->thumb_marker == '')
		{
			$this->thumb_marker = '';
		}

		$xp	= $this->explode_name($this->dest_image);
	
		$filename = $xp['name'];
		$file_ext = $xp['ext'];
				
		$this->full_src_path = $this->source_folder.$this->source_image;		
		$this->full_dst_path = $this->dest_folder.$filename.$this->thumb_marker.$file_ext;

		/*
		 * Should we maintain image proportions?
		 *
		 * When creating thumbs or copies, the target width/height
		 * might not be in correct proportion with the source
		 * image's width/height.  We'll recalculate it here.
		 *
		 */	
		if ($this->maintain_ratio === TRUE && ($this->width != '' AND $this->height != ''))
		{
			$this->image_reproportion();
		}

		/*
		 * Was a width and height specified?
		 *
		 * If the destination width/height was
		 * not submitted we will use the values
		 * from the actual file
		 *
		 */	
		if ($this->width == '')
			$this->width = $this->orig_width;
	
		if ($this->height == '')
			$this->height = $this->orig_height;
	
		// Set the quality
		$this->quality = trim(str_replace("%", "", $this->quality));
		
		if ($this->quality == '' OR $this->quality == 0 OR ! is_numeric($this->quality))
			$this->quality = 90;
	
		// Set the x/y coordinates
		$this->x_axis = ($this->x_axis == '' OR ! is_numeric($this->x_axis)) ? 0 : $this->x_axis;
		$this->y_axis = ($this->y_axis == '' OR ! is_numeric($this->y_axis)) ? 0 : $this->y_axis;
	
		// Watermark-related Stuff...
		if ($this->wm_font_color != '')
		{
			if (strlen($this->wm_font_color) == 6)
			{
				$this->wm_font_color = '#'.$this->wm_font_color;
			}
		}
		
		if ($this->wm_shadow_color != '')
		{
			if (strlen($this->wm_shadow_color) == 6)
			{
				$this->wm_shadow_color = '#'.$this->wm_shadow_color;
			}
		}
	
		if ($this->wm_overlay_path != '')
		{
			$this->wm_overlay_path = str_replace("\\", "/", realpath($this->wm_overlay_path));
		}
	
		if ($this->wm_shadow_color != '')
		{
			$this->wm_use_drop_shadow = TRUE;
		}

		if ($this->wm_font_path != '')
		{
			$this->wm_use_truetype = TRUE;
		}

		return TRUE;
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Image Resize
	 *
	 * This is a wrapper function that chooses the proper
	 * resize function based on the protocol specified
	 *
	 * @access	public
	 * @return	bool
	 */	
	function resize()
	{
		$protocol = 'image_process_'.$this->image_library;
		
		if (eregi("gd2$", $protocol))
		{
			$protocol = 'image_process_gd';
		}
		
		return $this->$protocol('resize');
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Image Crop
	 *
	 * This is a wrapper function that chooses the proper
	 * cropping function based on the protocol specified
	 *
	 * @access	public
	 * @return	bool
	 */	
	function crop()
	{
		$protocol = 'image_process_'.$this->image_library;
		
		if (eregi("gd2$", $protocol))
		{
			$protocol = 'image_process_gd';
		}
		
		return $this->$protocol('crop');
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Image Rotate
	 *
	 * This is a wrapper function that chooses the proper
	 * rotation function based on the protocol specified
	 *
	 * @access	public
	 * @return	bool
	 */	
	function rotate()
	{
		// Allowed rotation values		
		$degs = array(90, 180, 270, 'vrt', 'hor');	
	
		if ($this->rotation_angle == '' OR ! in_array($this->rotation_angle, $degs, TRUE))
		{
			$this->set_error('imglib_rotation_angle_required');
			return FALSE;	   	
		}
	
		// Reassign the width and height
		if ($this->rotation_angle == 90 OR $this->rotation_angle == 270)
		{
			$this->width	= $this->orig_height;
			$this->height	= $this->orig_width;
		}
		else
		{
			$this->width	= $this->orig_width;
			$this->height	= $this->orig_height;
		}
	

		// Choose resizing function
		if ($this->image_library == 'imagemagick' OR $this->image_library == 'netpbm')
		{
			$protocol = 'image_process_'.$this->image_library;
		
			return $this->$protocol('rotate');
		}
		
		if ($this->rotation_angle == 'hor' OR $this->rotation_angle == 'vrt')
		{
			return $this->image_mirror_gd();
		}
		else
		{		
			return $this->image_rotate_gd();
		}
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Image Process Using GD/GD2
	 *
	 * This function will resize or crop
	 *
	 * @access	public
	 * @param	string
	 * @return	bool
	 */		
	function image_process_gd($action = 'resize')
	{	
		$v2_override = FALSE;
			
		if ($action == 'crop')
		{
			// If the target width/height match the source then it's pointless to crop, right?
			// So if dynamic output isn't on, then we'll return true so the user thinks
			// the process succeeded. It'll be our little secret...

			if ($this->width >= $this->orig_width AND $this->height >= $this->orig_height AND $this->dynamic_output !== TRUE)
			{
				return TRUE;
			}

			//  Reassign the source width/height if cropping
			$this->orig_width  = $this->width;
			$this->orig_height = $this->height;	
				
			// GD 2.0 has a cropping bug so we'll test for it
			if ($this->gd_version() !== FALSE)
			{
				$gd_version = str_replace('0', '', $this->gd_version());			
				$v2_override = ($gd_version == 2) ? TRUE : FALSE;
			}
		}
		else
		{
			// If the target width/height match the source, AND if
			// the new file name is not equal to the old file name
			// we'll simply make a copy of the original with the new name		
			if (($this->orig_width == $this->width AND $this->orig_height == $this->height) AND ($this->source_image != $this->new_image))			
			{
				if ( ! @copy($this->full_src_path, $this->full_dst_path))
				{
					$this->set_error('imglib_copy_failed');
					return FALSE;
				}
			
				@chmod($this->full_dst_path, DIR_WRITE_MODE);
				return TRUE;
			}
			
			// If resizing the x/y axis must be zero
			$this->x_axis = 0;
			$this->y_axis = 0;
		}
		
		//  Create the image handle
		if ( ! ($src_img = $this->image_create_gd()))
		{		
			return FALSE;
		}

 		//  Create The Image
		//
		//  old conditional which users report cause problems with shared GD libs who report themselves as "2.0 or greater"
		//  it appears that this is no longer the issue that it was in 2004, so we've removed it, retaining it in the comment
		//  below should that ever prove inaccurate.
		//
		//  if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor') AND $v2_override == FALSE)
 		if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor'))		
		{
			$create	= 'imagecreatetruecolor';
			$copy	= 'imagecopyresampled';
		}
		else
		{
			$create	= 'imagecreate';	
			$copy	= 'imagecopyresized';
		}
			
		$dst_img = $create($this->width, $this->height);
		$copy($dst_img, $src_img, 0, 0, $this->x_axis, $this->y_axis, $this->width, $this->height, $this->orig_width, $this->orig_height);

		//  Show the image	
		if ($this->dynamic_output == TRUE)
		{
			$this->image_display_gd($dst_img);
		}
		else
		{
			// Or save it
			if ( ! $this->image_save_gd($dst_img))
			{
				return FALSE;
			}
		}

		//  Kill the file handles
		imagedestroy($dst_img);
		imagedestroy($src_img);
		
		// Set the file to 777
		@chmod($this->full_dst_path, DIR_WRITE_MODE);
		
		return TRUE;
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Image Process Using ImageMagick
	 *
	 * This function will resize, crop or rotate
	 *
	 * @access	public
	 * @param	string
	 * @return	bool
	 */		
	function image_process_imagemagick($action = 'resize')
	{
		//  Do we have a vaild library path?
		if ($this->library_path == '')
		{
			$this->set_error('imglib_libpath_invalid');
			return FALSE;
		}
				
		if ( ! eregi("convert$", $this->library_path))
		{
			if ( ! eregi("/$", $this->library_path)) $this->library_path .= "/";
		
			$this->library_path .= 'convert';
		}
		
		// Execute the command
		$cmd = $this->library_path." -quality ".$this->quality;
	
		if ($action == 'crop')
		{
			$cmd .= " -crop ".$this->width."x".$this->height."+".$this->x_axis."+".$this->y_axis." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1";
		}
		elseif ($action == 'rotate')
		{
			switch ($this->rotation_angle)
			{
				case 'hor' 	: $angle = '-flop';
					break;
				case 'vrt' 	: $angle = '-flip';
					break;
				default		: $angle = '-rotate '.$this->rotation_angle;
					break;
			}			
		
			$cmd .= " ".$angle." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1";
		}
		else  // Resize
		{
			$cmd .= " -resize ".$this->width."x".$this->height." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1";
		}
	
		$retval = 1;
	
		@exec($cmd, $output, $retval);

		//	Did it work?	
		if ($retval > 0)
		{
			$this->set_error('imglib_image_process_failed');
			return FALSE;
		}
		
		// Set the file to 777
		@chmod($this->full_dst_path, DIR_WRITE_MODE);
		
		return TRUE;
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Image Process Using NetPBM
	 *
	 * This function will resize, crop or rotate
	 *
	 * @access	public
	 * @param	string
	 * @return	bool
	 */		
	function image_process_netpbm($action = 'resize')
	{
		if ($this->library_path == '')
		{
			$this->set_error('imglib_libpath_invalid');
			return FALSE;
		}
			
		//  Build the resizing command
		switch ($this->image_type)
		{
			case 1 :
						$cmd_in		= 'giftopnm';
						$cmd_out	= 'ppmtogif';
				break;
			case 2 :
						$cmd_in		= 'jpegtopnm';
						$cmd_out	= 'ppmtojpeg';			
				break;
			case 3 :
						$cmd_in		= 'pngtopnm';
						$cmd_out	= 'ppmtopng';
				break;
		}
		
		if ($action == 'crop')
		{
			$cmd_inner = 'pnmcut -left '.$this->x_axis.' -top '.$this->y_axis.' -width '.$this->width.' -height '.$this->height;
		}
		elseif ($action == 'rotate')
		{
			switch ($this->rotation_angle)
			{
				case 90		:	$angle = 'r270';
					break;
				case 180	:	$angle = 'r180';
					break;
				case 270 	:	$angle = 'r90';
					break;
				case 'vrt'	:	$angle = 'tb';
					break;
				case 'hor'	:	$angle = 'lr';
					break;
			}
		
			$cmd_inner = 'pnmflip -'.$angle.' ';
		}
		else // Resize
		{
			$cmd_inner = 'pnmscale -xysize '.$this->width.' '.$this->height;
		}
						
		$cmd = $this->library_path.$cmd_in.' '.$this->full_src_path.' | '.$cmd_inner.' | '.$cmd_out.' > '.$this->dest_folder.'netpbm.tmp';
		
		$retval = 1;
		
		@exec($cmd, $output, $retval);
		
		//  Did it work?
		if ($retval > 0)
		{
			$this->set_error('imglib_image_process_failed');
			return FALSE;
		}
		
		// With NetPBM we have to create a temporary image.
		// If you try manipulating the original it fails so
		// we have to rename the temp file.
		copy ($this->dest_folder.'netpbm.tmp', $this->full_dst_path);
		unlink ($this->dest_folder.'netpbm.tmp');
		@chmod($dst_image, DIR_WRITE_MODE);
		
		return TRUE;
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Image Rotate Using GD
	 *
	 * @access	public
	 * @return	bool
	 */		
	function image_rotate_gd()
	{	
		// Is Image Rotation Supported?
		// this function is only supported as of PHP 4.3
		if ( ! function_exists('imagerotate'))
		{
			$this->set_error('imglib_rotate_unsupported');
			return FALSE;
		}
		
		//  Create the image handle
		if ( ! ($src_img = $this->image_create_gd()))
		{		
			return FALSE;
		}

		// Set the background color		
		// This won't work with transparent PNG files so we are
		// going to have to figure out how to determine the color
		// of the alpha channel in a future release.
	
		$white	= imagecolorallocate($src_img, 255, 255, 255);

		//  Rotate it!
		$dst_img = imagerotate($src_img, $this->rotation_angle, $white);
	
		//  Save the Image
		if ($this->dynamic_output == TRUE)
		{
			$this->image_display_gd($dst_img);
		}
		else
		{
			// Or save it
			if ( ! $this->image_save_gd($dst_img))
			{
				return FALSE;
			}
		}

		//  Kill the file handles
		imagedestroy($dst_img);
		imagedestroy($src_img);
		
		// Set the file to 777
		
		@chmod($this->full_dst_path, DIR_WRITE_MODE);
		
		return true;
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Create Mirror Image using GD
	 *
	 * This function will flip horizontal or vertical
	 *
	 * @access	public
	 * @return	bool
	 */			
	function image_mirror_gd()
	{		
		if ( ! $src_img = $this->image_create_gd())
		{
			return FALSE;
		}
		
		$width  = $this->orig_width;
		$height = $this->orig_height;
	
		if ($this->rotation_angle == 'hor')
		{
			for ($i = 0; $i < $height; $i++)
			{
				$left  = 0;
				$right = $width-1;
	
				while ($left < $right)
				{
					$cl = imagecolorat($src_img, $left, $i);
					$cr = imagecolorat($src_img, $right, $i);
					
					imagesetpixel($src_img, $left, $i, $cr);
					imagesetpixel($src_img, $right, $i, $cl);
					
					$left++;
					$right--;
				}
			}
		}
		else
		{
			for ($i = 0; $i < $width; $i++)
			{
				$top = 0;
				$bot = $height-1;
	
				while ($top < $bot)
				{
					$ct = imagecolorat($src_img, $i, $top);
					$cb = imagecolorat($src_img, $i, $bot);
					
					imagesetpixel($src_img, $i, $top, $cb);
					imagesetpixel($src_img, $i, $bot, $ct);
					
					$top++;
					$bot--;
				}
			}		
		}		

		//  Show the image
		if ($this->dynamic_output == TRUE)
		{
			$this->image_display_gd($src_img);
		}
		else
		{
			// Or save it
			if ( ! $this->image_save_gd($src_img))
			{
				return FALSE;
			}
		}
		
		//  Kill the file handles
		imagedestroy($src_img);
		
		// Set the file to 777
		@chmod($this->full_dst_path, DIR_WRITE_MODE);
		
		return TRUE;
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Image Watermark
	 *
	 * This is a wrapper function that chooses the type
	 * of watermarking based on the specified preference.
	 *
	 * @access	public
	 * @param	string
	 * @return	bool
	 */	
	function watermark()
	{
		if ($this->wm_type == 'overlay')
		{
			return $this->overlay_watermark();
		}
		else
		{
			return $this->text_watermark();
		}
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Watermark - Graphic Version
	 *
	 * @access	public
	 * @return	bool
	 */			
	function overlay_watermark()
	{
		if ( ! function_exists('imagecolortransparent'))
		{
			$this->set_error('imglib_gd_required');
			return FALSE;		
		}
	
		//  Fetch source image properties
		$this->get_image_properties();

		//  Fetch watermark image properties
		$props 			= $this->get_image_properties($this->wm_overlay_path, TRUE);	
		$wm_img_type	= $props['image_type'];
		$wm_width		= $props['width'];
		$wm_height		= $props['height'];
	
		//  Create two image resources	
		$wm_img  = $this->image_create_gd($this->wm_overlay_path, $wm_img_type);
		$src_img = $this->image_create_gd($this->full_src_path);
		
		// Reverse the offset if necessary		
		// When the image is positioned at the bottom
		// we don't want the vertical offset to push it
		// further down.  We want the reverse, so we'll
		// invert the offset.  Same with the horizontal
		// offset when the image is at the right
		
		$this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1));
		$this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1));
	
		if ($this->wm_vrt_alignment == 'B')
			$this->wm_vrt_offset = $this->wm_vrt_offset * -1;
	
		if ($this->wm_hor_alignment == 'R')
			$this->wm_hor_offset = $this->wm_hor_offset * -1;

		//  Set the base x and y axis values
		$x_axis = $this->wm_hor_offset + $this->wm_padding;
		$y_axis = $this->wm_vrt_offset + $this->wm_padding;

		//  Set the vertical position
		switch ($this->wm_vrt_alignment)
		{
			case 'T':
				break;
			case 'M':	$y_axis += ($this->orig_height / 2) - ($wm_height / 2);
				break;
			case 'B':	$y_axis += $this->orig_height - $wm_height;
				break;
		}

		//  Set the horizontal position
		switch ($this->wm_hor_alignment)
		{
			case 'L':
				break;	
			case 'C':	$x_axis += ($this->orig_width / 2) - ($wm_width / 2);
				break;
			case 'R':	$x_axis += $this->orig_width - $wm_width;
				break;
		}
	
		//  Build the finalized image			
		if ($wm_img_type == 3 AND function_exists('imagealphablending'))
		{
			@imagealphablending($src_img, TRUE);
		} 		
		
		// Set RGB values for text and shadow
		$rgba = imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp);
		$alpha = ($rgba & 0x7F000000) >> 24;
		
		// make a best guess as to whether we're dealing with an image with alpha transparency or no/binary transparency
		if ($alpha > 0)
		{
			// copy the image directly, the image's alpha transparency being the sole determinant of blending
			imagecopy($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height);
		}
		else
		{
			// set our RGB value from above to be transparent and merge the images with the specified opacity
			imagecolortransparent($wm_img, imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp));
			imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity);			
		}
				
		//  Output the image
		if ($this->dynamic_output == TRUE)
		{
			$this->image_display_gd($src_img);
		}
		else
		{
			if ( ! $this->image_save_gd($src_img))
			{
				return FALSE;
			}
		}
		
		imagedestroy($src_img);
		imagedestroy($wm_img);
				
		return TRUE;
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Watermark - Text Version
	 *
	 * @access	public
	 * @return	bool
	 */			
	function text_watermark()
	{
		if ( ! ($src_img = $this->image_create_gd()))
		{		
			return FALSE;
		}
				
		if ($this->wm_use_truetype == TRUE AND ! file_exists($this->wm_font_path))
		{
			$this->set_error('imglib_missing_font');
			return FALSE;
		}
		
		//  Fetch source image properties		
		$this->get_image_properties();				
		
		// Set RGB values for text and shadow		
		$this->wm_font_color	= str_replace('#', '', $this->wm_font_color);
		$this->wm_shadow_color	= str_replace('#', '', $this->wm_shadow_color);
		
		$R1 = hexdec(substr($this->wm_font_color, 0, 2));
		$G1 = hexdec(substr($this->wm_font_color, 2, 2));
		$B1 = hexdec(substr($this->wm_font_color, 4, 2));
	
		$R2 = hexdec(substr($this->wm_shadow_color, 0, 2));
		$G2 = hexdec(substr($this->wm_shadow_color, 2, 2));
		$B2 = hexdec(substr($this->wm_shadow_color, 4, 2));
		
		$txt_color	= imagecolorclosest($src_img, $R1, $G1, $B1);
		$drp_color	= imagecolorclosest($src_img, $R2, $G2, $B2);

		// Reverse the vertical offset
		// When the image is positioned at the bottom
		// we don't want the vertical offset to push it
		// further down.  We want the reverse, so we'll
		// invert the offset.  Note: The horizontal
		// offset flips itself automatically
	
		if ($this->wm_vrt_alignment == 'B')
			$this->wm_vrt_offset = $this->wm_vrt_offset * -1;
			
		if ($this->wm_hor_alignment == 'R')
			$this->wm_hor_offset = $this->wm_hor_offset * -1;

		// Set font width and height
		// These are calculated differently depending on
		// whether we are using the true type font or not
		if ($this->wm_use_truetype == TRUE)
		{
			if ($this->wm_font_size == '')
				$this->wm_font_size = '17';
		
			$fontwidth  = $this->wm_font_size-($this->wm_font_size/4);
			$fontheight = $this->wm_font_size;
			$this->wm_vrt_offset += $this->wm_font_size;
		}
		else
		{
			$fontwidth  = imagefontwidth($this->wm_font_size);
			$fontheight = imagefontheight($this->wm_font_size);
		}

		// Set base X and Y axis values
		$x_axis = $this->wm_hor_offset + $this->wm_padding;
		$y_axis = $this->wm_vrt_offset + $this->wm_padding;

		// Set verticle alignment
		if ($this->wm_use_drop_shadow == FALSE)
			$this->wm_shadow_distance = 0;
			
		$this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1));
		$this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1));
	
		switch ($this->wm_vrt_alignment)
		{
			case	 "T" :
				break;
			case "M":	$y_axis += ($this->orig_height/2)+($fontheight/2);
				break;
			case "B":	$y_axis += ($this->orig_height - $fontheight - $this->wm_shadow_distance - ($fontheight/2));
				break;
		}
	
		$x_shad = $x_axis + $this->wm_shadow_distance;
		$y_shad = $y_axis + $this->wm_shadow_distance;
		
		// Set horizontal alignment
		switch ($this->wm_hor_alignment)
		{
			case "L":
				break;
			case "R":
						if ($this->wm_use_drop_shadow)
							$x_shad += ($this->orig_width - $fontwidth*strlen($this->wm_text));
							$x_axis += ($this->orig_width - $fontwidth*strlen($this->wm_text));
				break;
			case "C":
						if ($this->wm_use_drop_shadow)
							$x_shad += floor(($this->orig_width - $fontwidth*strlen($this->wm_text))/2);
							$x_axis += floor(($this->orig_width  -$fontwidth*strlen($this->wm_text))/2);
				break;
		}
		
		//  Add the text to the source image
		if ($this->wm_use_truetype)
		{	
			if ($this->wm_use_drop_shadow)
				imagettftext($src_img, $this->wm_font_size, 0, $x_shad, $y_shad, $drp_color, $this->wm_font_path, $this->wm_text);
				imagettftext($src_img, $this->wm_font_size, 0, $x_axis, $y_axis, $txt_color, $this->wm_font_path, $this->wm_text);
		}
		else
		{
			if ($this->wm_use_drop_shadow)
				imagestring($src_img, $this->wm_font_size, $x_shad, $y_shad, $this->wm_text, $drp_color);
				imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color);
		}
	
		//  Output the final image
		if ($this->dynamic_output == TRUE)
		{
			$this->image_display_gd($src_img);
		}
		else
		{
			$this->image_save_gd($src_img);
		}
		
		imagedestroy($src_img);
	
		return TRUE;
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Create Image - GD
	 *
	 * This simply creates an image resource handle
	 * based on the type of image being processed
	 *
	 * @access	public
	 * @param	string
	 * @return	resource
	 */			
	function image_create_gd($path = '', $image_type = '')
	{
		if ($path == '')
			$path = $this->full_src_path;
			
		if ($image_type == '')
			$image_type = $this->image_type;
	
		
		switch ($image_type)
		{
			case	 1 :
						if ( ! function_exists('imagecreatefromgif'))
						{
							$this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported'));
							return FALSE;
						}
					
						return imagecreatefromgif($path);
				break;
			case 2 :
						if ( ! function_exists('imagecreatefromjpeg'))
						{
							$this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported'));
							return FALSE;
						}
					
						return imagecreatefromjpeg($path);
				break;
			case 3 :
						if ( ! function_exists('imagecreatefrompng'))
						{
							$this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported'));				
							return FALSE;
						}
					
						return imagecreatefrompng($path);
				break;			
		
		}
		
		$this->set_error(array('imglib_unsupported_imagecreate'));
		return FALSE;
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Write image file to disk - GD
	 *
	 * Takes an image resource as input and writes the file
	 * to the specified destination
	 *
	 * @access	public
	 * @param	resource
	 * @return	bool
	 */			
	function image_save_gd($resource)
	{	
		switch ($this->image_type)
		{
			case 1 :
						if ( ! function_exists('imagegif'))
						{
							$this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported'));
							return FALSE;		
						}
						
						@imagegif($resource, $this->full_dst_path);
				break;
			case 2	:
						if ( ! function_exists('imagejpeg'))
						{
							$this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported'));
							return FALSE;		
						}
						
						if (phpversion() == '4.4.1')
						{
							@touch($this->full_dst_path); // PHP 4.4.1 bug #35060 - workaround
						}
						
						@imagejpeg($resource, $this->full_dst_path, $this->quality);
				break;
			case 3	:
						if ( ! function_exists('imagepng'))
						{
							$this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported'));
							return FALSE;		
						}
					
						@imagepng($resource, $this->full_dst_path);
				break;
			default		:
							$this->set_error(array('imglib_unsupported_imagecreate'));
							return FALSE;		
				break;		
		}
	
		return TRUE;
	}	
	
	// --------------------------------------------------------------------
	
	/**
	 * Dynamically outputs an image
	 *
	 * @access	public
	 * @param	resource
	 * @return	void
	 */			
	function image_display_gd($resource)
	{		
		header("Content-Disposition: filename={$this->source_image};");
		header("Content-Type: {$this->mime_type}");
		header('Content-Transfer-Encoding: binary');
		header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT');
	
		switch ($this->image_type)
		{
			case 1 		:	imagegif($resource);
				break;
			case 2		:	imagejpeg($resource, '', $this->quality);
				break;
			case 3		:	imagepng($resource);
				break;
			default		:	echo 'Unable to display the image';
				break;		
		}			
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Re-proportion Image Width/Height
	 *
	 * When creating thumbs, the desired width/height
	 * can end up warping the image due to an incorrect
	 * ratio between the full-sized image and the thumb.
	 *
	 * This function lets us re-proportion the width/height
	 * if users choose to maintain the aspect ratio when resizing.
	 *
	 * @access	public
	 * @return	void
	 */			
	function image_reproportion()
	{
		if ( ! is_numeric($this->width) OR ! is_numeric($this->height) OR $this->width == 0 OR $this->height == 0)
			return;
		
		if ( ! is_numeric($this->orig_width) OR ! is_numeric($this->orig_height) OR $this->orig_width == 0 OR $this->orig_height == 0)
			return;
		
		$new_width	= ceil($this->orig_width*$this->height/$this->orig_height);		
		$new_height	= ceil($this->width*$this->orig_height/$this->orig_width);
		
		$ratio = (($this->orig_height/$this->orig_width) - ($this->height/$this->width));
	
		if ($this->master_dim != 'width' AND $this->master_dim != 'height')
		{
			$this->master_dim = ($ratio < 0) ? 'width' : 'height';
		}
		
		if (($this->width != $new_width) AND ($this->height != $new_height))
		{
			if ($this->master_dim == 'height')
			{
				$this->width = $new_width;
			}
			else
			{
				$this->height = $new_height;
			}
		}
	}	
	
	// --------------------------------------------------------------------
	
	/**
	 * Get image properties
	 *
	 * A helper function that gets info about the file
	 *
	 * @access	public
	 * @param	string
	 * @return	mixed
	 */			
	function get_image_properties($path = '', $return = FALSE)
	{
		// For now we require GD but we should
		// find a way to determine this using IM or NetPBM
		
		if ($path == '')
			$path = $this->full_src_path;
				
		if ( ! file_exists($path))
		{
			$this->set_error('imglib_invalid_path');		
			return FALSE;				
		}
		
		$vals = @getimagesize($path);
		
		$types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png');
		
		$mime = (isset($types[$vals['2']])) ? 'image/'.$types[$vals['2']] : 'image/jpg';
				
		if ($return == TRUE)
		{
			$v['width']			= $vals['0'];
			$v['height']		= $vals['1'];
			$v['image_type']	= $vals['2'];
			$v['size_str']		= $vals['3'];
			$v['mime_type']		= $mime;
			
			return $v;
		}
		
		$this->orig_width	= $vals['0'];
		$this->orig_height	= $vals['1'];
		$this->image_type	= $vals['2'];
		$this->size_str		= $vals['3'];
		$this->mime_type	= $mime;
		
		return TRUE;
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Size calculator
	 *
	 * This function takes a known width x height and
	 * recalculates it to a new size.  Only one
	 * new variable needs to be known
	 *
	 *	$props = array(
	 *					'width' 		=> $width,
	 *					'height' 		=> $height,
	 *					'new_width'		=> 40,
	 *					'new_height'	=> ''
	 *				  );
	 *
	 * @access	public
	 * @param	array
	 * @return	array
	 */			
	function size_calculator($vals)
	{
		if ( ! is_array($vals))
			return;
			
		$allowed = array('new_width', 'new_height', 'width', 'height');
	
		foreach ($allowed as $item)
		{
			if ( ! isset($vals[$item]) OR $vals[$item] == '')
				$vals[$item] = 0;
		}
		
		if ($vals['width'] == 0 OR $vals['height'] == 0)
		{
			return $vals;
		}
			
		if ($vals['new_width'] == 0)
		{
			$vals['new_width'] = ceil($vals['width']*$vals['new_height']/$vals['height']);
		}
		elseif ($vals['new_height'] == 0)
		{
			$vals['new_height'] = ceil($vals['new_width']*$vals['height']/$vals['width']);
		}
	
		return $vals;
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Explode source_image
	 *
	 * This is a helper function that extracts the extension
	 * from the source_image.  This function lets us deal with
	 * source_images with multiple periods, like:  my.cool.jpg
	 * It returns an associative array with two elements:
	 * $array['ext']  = '.jpg';
	 * $array['name'] = 'my.cool';
	 *
	 * @access	public
	 * @param	array
	 * @return	array
	 */	
	function explode_name($source_image)
	{
		$x = explode('.', $source_image);
		$ret['ext'] = '.'.end($x);
		
		$name = '';
		
		$ct = count($x)-1;
		
		for ($i = 0; $i < $ct; $i++)
		{
			$name .= $x[$i];
			
			if ($i < ($ct - 1))
			{
				$name .= '.';
			}
		}
		
		$ret['name'] = $name;
		
		return $ret;
	}	
	
	// --------------------------------------------------------------------
	
	/**
	 * Is GD Installed?
	 *
	 * @access	public
	 * @return	bool
	 */	
	function gd_loaded()
	{
		if ( ! extension_loaded('gd'))
		{
			if ( ! dl('gd.so'))
			{
				return FALSE;
			}
		}
		
		return TRUE;
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Get GD version
	 *
	 * @access	public
	 * @return	mixed
	 */	
	function gd_version()
	{
		if (function_exists('gd_info'))
		{
			$gd_version = @gd_info();
			$gd_version = preg_replace("/\D/", "", $gd_version['GD Version']);
			
			return $gd_version;
		}
		
		return FALSE;
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Set error message
	 *
	 * @access	public
	 * @param	string
	 * @return	void
	 */	
	function set_error($msg)
	{
		$CI =& get_instance();
		$CI->lang->load('imglib');
		
		if (is_array($msg))
		{
			foreach ($msg as $val)
			{
				
				$msg = ($CI->lang->line($val) == FALSE) ? $val : $CI->lang->line($val);
				$this->error_msg[] = $msg;
				log_message('error', $msg);
			}		
		}
		else
		{
			$msg = ($CI->lang->line($msg) == FALSE) ? $msg : $CI->lang->line($msg);
			$this->error_msg[] = $msg;
			log_message('error', $msg);
		}
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Show error messages
	 *
	 * @access	public
	 * @param	string
	 * @return	string
	 */	
	function display_errors($open = '<p>', $close = '</p>')
	{	
		$str = '';
		foreach ($this->error_msg as $val)
		{
			$str .= $open.$val.$close;
		}
	
		return $str;
	}

}
// END Image_lib Class

/* End of file Image_lib.php */
/* Location: ./system/libraries/Image_lib.php */


En attendant, je file voir mon pote :wobble-18a4:
 
Dernière édition:
j'ai fait une recherche vite fait sur le site de PHP
la fonction eregi() est obsolète et il semble qu'il faille la remplacer par la fonction preg_match()
en discutant avec ton pote, il m'a filé ça

et c'est ce bout de code qui m'a l'air le mieux, je ferai mes tests des que je pourrai :icon_wink-221e:

PHP:
if ( ! preg_match("#convert$#i", $this->library_path)) {
        if ( ! preg_match("#/$#i", $this->library_path))
                 $this->library_path .= "/";
        $this->library_path .= 'convert';}

if (preg_match("#gd2$#i", $protocol)) {
       $protocol = 'image_process_gd'; }
 
Dernière édition:
Depuis plusieurs jours je galère avec ce script, qui fonctionnait parfaitement sous PHP 5.2 & depuis le passage à PHP 5.3, plus RIEN !!!

Ah ça, je t'avais bien dit que PHP 5.3 était chiant au possible :lol-1923: C'est saoulant qu'ils déprécient les références, car c'est hyper pratique quand c'est bien utilisé !

Question pour Mr Fox! Tout est correct dans les codes donnés plus haut ? :confused-188a:

Comme le dit Gollum, ça m'a l'air correct ce qu'ils disent :sourire-4e62:

la fonction eregi() est obsolète et il semble qu'il faille la remplacer par la fonction preg_match()

En effet, avant il existait deux moteurs de regex pour PHP : le moteur C avec la suite de fonctions ereg et le moteur POSIX (issu de Perl) avec la suite de fonctions preg. A la base, PHP est issu de Perl, donc le moteur POSIX est bien plus performant. De plus, l'implémentation du moteur C dans PHP à été abandonné après la version 4.1 de PHP. C'est pourquoi le moteur C est à présent déclaré comme obsolète.
 
Statut
La discussion n'est pas ouverte à d'autres réponses
Retour
Haut