[ Index ]

PHP Cross Reference of IEUF

title

Body

[close]

/Pages/media/ -> trait_images.inc.php (source)

   1  <?php
   2    function genereNomFicBase() {
   3      global $mysqli, $id_representation;
   4          $requete="SELECT spectacle.titre as titre_spect, DATE_FORMAT(representation.date,'%Y%m%d') as date_repr"
   5             . " FROM spectacle, representation "
   6             . "WHERE representation.id='$id_representation' AND spectacle.id=id_spectacle";
   7      $recherche=$mysqli->query($requete);
   8      if($recherche===false) die('erreur BD');
   9      if (($champs=$recherche->fetch_assoc()) === NULL) 
  10        die('erreur BD');
  11      extract ($champs);
  12      $nomFic= strstr("$date_repr$titre_spect ".$_FILES['inputImage']['name'],'.',TRUE);
  13      
  14      //http://stackoverflow.com/questions/8315740/how-to-remove-accent-from-characters-leave-only-english-alphabet-glyphs
  15      //ATTENTION la page est en UTF8, ici la table est un peu modifiée'
  16      $tabConv= array(
  17          ' ' => '@/|"|\\\|\*|\?|\'|<|>|\|@',
  18          '_' => '@&|%|`|´|\^|~|¨|ª|º|©|®@',
  19          'a' => '@à|á|â|ã|ä|å|æ@', 
  20          'e' => '@è|é|ê|ë@', 
  21          'i' => '@ì|í|î|ï@',   
  22          'o' => '@ò|ó|ô|õ|ö|ø@', 
  23          'u' => '@ù|ú|û|ü@', 
  24          'A' => '@À|Á|Â|Ã|Ä|Å|Æ@', 
  25          'E' => '@È|É|Ê|Ë@', 
  26          'I' => '@Ì|Í|Î|Ï@',   
  27          'O' => '@Ò|Ó|Ô|Õ|Ö|Ø@', 
  28          'U' => '@Ù|Ú|Û|Ü@', 
  29          'c' => '@ç@', 
  30          'C' => '@Ç@', 
  31          'n' => '@ñ@', 
  32          'N' => '@Ñ@', 
  33          'y' => '@ý|ÿ@', 
  34          'Y' => '/Ý/'
  35        );
  36      $nomFic= preg_replace($tabConv, array_keys($tabConv), $nomFic);
  37      for ($i= 0; $i <= strlen($nomFic); $i++)
  38        if (ord($nomFic[$i]) > 127) $nomFic[$i]= '_';
  39      return $nomFic;
  40    }
  41    
  42  $nom_fic= genereNomFicBase();
  43  echo("<p>$nom_fic</p>");
  44  
  45  if ($_FILES['inputImage']['type'] == "image/png") {
  46    $ext=".png";
  47    $gd_org = imagecreatefrompng($_FILES['inputImage']['tmp_name']);
  48  }
  49  elseif ($_FILES['inputImage']['type'] == "image/jpeg") {
  50    $ext=".jpg";
  51    $gd_org = imagecreatefromjpeg($_FILES['inputImage']['tmp_name']);
  52  }
  53  $suf=0;
  54  $sfxVid= "";
  55  if (isset($_FILES['inputVideo'])) {
  56    $sfxVid= ".webm";
  57    $ext=".jpg";
  58  }
  59  
  60  do {
  61      $suf++;
  62  } while (file_exists("$repPetites$nom_fic$suf$sfxVid$ext"));
  63  $nom_fic .= $suf;
  64  echo("<p>$nom_fic</p>");
  65  
  66  
  67  $lg_org= imagesx($gd_org);
  68  $ht_org= imagesy($gd_org);
  69  
  70  function creeImage ($lgDest, $htDest, $lgOrig, $htOrig, $gdOrig, $marge) {
  71      $rx= ($lgDest - 2*$marge) / $lgOrig;
  72      $ry= $htDest / $htOrig;
  73      $ratio = $rx < $ry ? $rx : $ry;
  74      $lg_new = floor($lgOrig * $ratio);
  75      $ht_new = floor($htOrig * $ratio);
  76      $gd_new= imagecreatetruecolor($lgDest, $htDest);
  77      $x = floor(($lgDest - $lg_new)/2);
  78      $y = floor(($htDest - $ht_new)/2);
  79      imagecopyresampled($gd_new, $gdOrig, $x, $y, 0, 0, $lg_new, $ht_new, $lgOrig, $htOrig);
  80      return $gd_new;
  81  }
  82  
  83  if ($sfxVid == "")
  84      $gd_new = creeImage($largeurPetites, $hauteurPetites, $lg_org, $ht_org, $gd_org, 0);
  85  else {
  86      $gd_trou = imagecreatefrompng("perfoFilm.png");
  87      $ht_trou = imagesy($gd_trou);
  88      $lg_trou = imagesx($gd_trou);
  89      $gd_new = creeImage($largeurPetites, $hauteurPetites, $lg_org, $ht_org, $gd_org, $lg_trou);
  90      for ($y=0; $y<$hauteurPetites; $y+=$ht_trou) {
  91          imagecopy ($gd_new, $gd_trou, 0, $y, 0, 0, $lg_trou, $ht_trou);
  92          imagecopy ($gd_new, $gd_trou, $largeurPetites-$lg_trou, $y, 0, 0, $lg_trou, $ht_trou);
  93      }
  94  }
  95  if ($ext == ".png")
  96    imagepng($gd_new, "$repPetites$nom_fic$sfxVid$ext");
  97  else
  98    imagejpeg($gd_new, "$repPetites$nom_fic$sfxVid$ext");
  99  
 100  $gd_new = creeImage($largeurMoyennes, $hauteurMoyennes, $lg_org, $ht_org, $gd_org, 0);
 101  if ($ext == ".png")
 102    imagepng($gd_new, "$repMoyennes$nom_fic$sfxVid$ext");
 103  else
 104    imagejpeg($gd_new, "$repMoyennes$nom_fic$sfxVid$ext");
 105  
 106  if (isset($_FILES['inputVideo'])) {
 107    $chemin= $nom_fic.$sfxVid;
 108    copy($_FILES['inputVideo']['tmp_name'], $repVideo.$chemin);
 109  }
 110  else {
 111    $chemin= $nom_fic.$ext;
 112    if (isset($_POST['grande']))
 113      copy($_FILES['inputImage']['tmp_name'], $repGrandes.$chemin);
 114  }
 115  ?>


Generated: Fri Jan 31 19:59:00 2014 Cross-referenced by PHPXref 0.7.1