Location: PHPKode > projects > Phpress > phpress/article_images.php
<?
/*
    Copyright (C)2004-2007  Matthieu Perez - hide@address.com

    This file is part of PhPress.

    PhPress is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    PhPress is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with PhPress.  If not, see <http://www.gnu.org/licenses/>.
*/
/////////////////////////
// article_images.php
//  display articles as images
session_start();

require 'program/common/constantes.php' ;
require LANG_PATH . $lang ."/msg.php";
require PROG_COM_PATH .'functions_mysql.php';
require PROG_COM_PATH . 'functions_common.php';
require 'program/html/default.css';
//require 'program/html/lightblue.css';
//require 'program/html/lightyellow2.css';

// article : full or by blocks ?
if($chg_art_dislay=='IMG')
{
$print_article='Y';
setcookie('print_article', 'Y');
}
else if($chg_art_dislay=='BLK')
{
$print_article='N';
setcookie('print_article', 'N');
}


if($print_article=='Y')
{
$txt_img_article=TXT_BLK_ARTICLE;
$chg_art_dislay='BLK';
}
else
{
$txt_img_article=TXT_IMG_ARTICLE;
$chg_art_dislay='IMG';
}

//form
print '<TABLE width="100%"><FORM>
      <input type="hidden" name="article_id" value="'.$article_id.'">
      <input type="hidden" name="chg_art_dislay" value="'.$chg_art_dislay.'">    
      <tr align="center">
      <td></td>
      <td width="50%">
      <INPUT type="submit" value="'.$txt_img_article.'" style="width: 100%;">
      </td></form>
      <td></td>      
      </tr></table><hr>';

//sql
   $request="SELECT NPTitle, JDay, Page, SurfRelPage, Surface_mm from Articles WHERE IdArticle='$article_id'";
   $query_result=sql_request($db, $request) ; 
   $result=mysql_fetch_array($query_result) ;
   $art_npid = $result[0] ;
   $jday = $result[1] ;
   $page = $result[2];
   $surf = $result[3];
   $formated_surf=num_format($lang, $surf, 2);
   $mm_surf=num_format($lang, $result[4], 0);
   
  $request="SELECT * from Blocks WHERE IdArticle='$article_id'";
  $query_result=sql_request($db, $request) ; 

  while($result=mysql_fetch_array($query_result))
  {
  $id_block=$result[0];
  $originfile=$result[1];
  $CurrentAx = $result[2] ;
     
  $block_X=$result[14];
  $block_Y=$result[15];
  
  $originpath=get_filepath($db, $art_npid, $originfile, $jday, png);
  
  $block_path= get_blockpath($db, $id_block, $originfile);
  
 if(!file_exists($originpath))
 {
  print '<red>'.TXT_NO_ORIGIN.' :</red> <blue>'.$originfile.'</blue>';
 }
 else
 {
     //$CurrentIdBlock = $GetCurrentBlockCoord_result[0]  ;
     $CurrentAy = $result[3] ;
     $CurrentBx = $result[4] ;
     $CurrentBy = $result[5] ;
     $CurrentCx = $result[6] ;
     $CurrentCy = $result[7] ;
     $CurrentDx = $result[8] ;
     $CurrentDy = $result[9] ;
     
     $CurrentBlockUserName = $result[11]  ;
    
     // point le plus haut
     if($CurrentAy <= $CurrentBy)
     {
     $HigherPoint = $CurrentAy ;
     }
     else
     {
     $HigherPoint = $CurrentBy ;
     }
     
     // point le plus bas
     if($CurrentDy >= $CurrentCy)
     {
     $LowerPoint = $CurrentDy ;
     }
     else
     {
     $LowerPoint = $CurrentCy ;
     }
     
     // point le plus à gauche
     if($CurrentAx <= $CurrentDx)
     {
     $LeftPoint = $CurrentAx ;
     }
     else
     {
     $LeftPoint = $CurrentDx ;
     }
     
     // point le plus à droite
     if($CurrentBx >= $CurrentCx)
     {
     $RightPoint = $CurrentBx ;
     }
     else
     {
     $RightPoint = $CurrentCx ;
     }
     
     // géométrie de l'image à créer :
     // point de départ :
     $src_X = $LeftPoint ;
     $src_Y = $HigherPoint ;
     
     // largeur :
     $src_W = ($RightPoint - $LeftPoint);
     // hauteur :
     $src_H = ($LowerPoint - $HigherPoint) ;
          
        if(!$block_Y)
        {     
        // update blocks table for X and Y cols
         $urequest="UPDATE Blocks SET ImageX = '$src_W', ImageY = '$src_H' WHERE IdBlock='$id_block'";
        $uquery_result=sql_request($db, $urequest) ; 
        $block_X=$src_W; 
        $block_Y=$src_H;
        }
    
     //hauteurs
     $AyDy = ($CurrentDy - $CurrentAy);
     $ByCy = ($CurrentBy - $CurrentDy);

     // create image if it doesn't exist
     if(!file_exists($block_path)) // OR !$block_X)
     {
   //header ("Content-type: image/png");
     $im = imagecreatetruecolor($src_W, $src_H);
          
          $file=$block_path;
          
     $original=imagecreatefrompng($originpath);
     imagecopy($im, $original, 0, 0, $src_X, $src_Y, $src_W, $src_H);
     
     imagepng($im, $file);  
        
     imagedestroy ($original);
     imagedestroy ($im);
     }

     // zoom
   if($block_zoom_ratio)
   {
   $display_block_width_zoomed=(int)($block_X * $block_zoom_ratio / 100);
   $display_block_height_zoomed=(int)($block_Y * $block_zoom_ratio / 100);
   }
   else if(!$block_zoom_ratio AND $zoom_ratio)
   {
   $display_block_width_zoomed=(int)($block_X * $zoom_ratio / 100);
   $display_block_height_zoomed=(int)($block_Y * $zoom_ratio / 100);
   }
   else
   {
   $display_block_width_zoomed=$block_X;
   $display_block_height_zoomed=$block_Y;
   }

/////////////////////////////////////////////////////////////////////////////////////
// ici on décide si on affiche par bloc ou par article
  if(!$print_article){$print_article='N';}
  
  if($print_article=='N')
  {
 // print ' bloc : '.$block_path.' - block_Y='.$block_Y.'<br>';
    print '<blue>'.TXT_BLOCK.'&nbsp;'.$id_block.'</blue>&nbsp;:<br>';
  
    print '<IMG src="'.$block_path.'" alt="block '.$id_block.'" width="'.$display_block_width_zoomed.'" height="'.$display_block_height_zoomed.'" border="0"><br><br>
  ';
  }
  
  }
  
 // ici on prépare les dimensions de l'image 
  if($print_article=='Y')
  {
   // point le plus haut
   if(!$ImgHigherPoint)
    {     $ImgHigherPoint = $HigherPoint ;     }
   else if($ImgHigherPoint > $HigherPoint)
    {     $ImgHigherPoint = $HigherPoint ;     }
    
     // point le plus bas
    if(!$ImgLowerPoint)
    {     $ImgLowerPoint = $LowerPoint ;     }     
    else if($ImgLowerPoint < $LowerPoint)
    {     $ImgLowerPoint = $LowerPoint ;     }
    
     // point le plus à gauche
    if(!$ImgLeftPoint)
    {     $ImgLeftPoint = $LeftPoint ;     }               
    else if($ImgLeftPoint > $LeftPoint)
    {     $ImgLeftPoint = $LeftPoint ;     }

     // point le plus à droite
    if(!$ImgRightPoint)
    {     $ImgRightPoint = $RightPoint ;     }    
    else if($ImgRightPoint < $RightPoint)
    {     $ImgRightPoint = $RightPoint ;     }

  }
 }
 
 if($print_article=='Y')
  {  
  // image :
     $ImgHigherPointModif=$ImgHigherPoint-35;
  // largeur :
     $img_W = ($ImgRightPoint - $ImgLeftPoint);
  // hauteur :
     $img_H = ($ImgLowerPoint - $ImgHigherPointModif) ;

  // creation de l'image
   $img = imagecreatetruecolor($img_W, $img_H);
   
   $bgcolor = imagecolorallocate($img, 0,255,0);
   $transp = imagecolortransparent ($img, $bgcolor);
   $textcolor = imagecolorallocate($img, 0, 0, 255);
   $black = imagecolorallocate($img, 0,0,0);
   $red = imagecolorallocate($img, 255, 69, 0);
   
   imagefilledrectangle ($img, 0, 0, $img_W, $img_H, $bgcolor);
   // titre de l'image 
   $gdate = get_gdate($lang, $jday);
   $npname = get_np_name($db, $art_npid);
   
   $text_np = "$npname - Art. $article_id";
   $text_art="$gdate p. $page - $mm_surf mm2 - $formated_surf%"   ; 
    
   imagestring($img, 3, 3, 0, $text_np, $red);
   imagestring($img, 3, 3, 13, $text_art, $textcolor);
   
   // blocs
   $request="SELECT * from Blocks WHERE IdArticle='$article_id'";
   $query_result=sql_request($db, $request) ; 

   while($result=mysql_fetch_array($query_result))
   {
   $id_block=$result[0];
   $originfile=$result[1];
   
   $Ax = $result[2] ; 
   $Ay = $result[3] ; 
   $Bx = $result[4] ; 
   $By = $result[5] ;
   $Cx = $result[6] ;
   $Cy = $result[7] ;  
   $Dx = $result[8] ;
   $Dy = $result[9] ;
   
   if($Ax < $Dx){ $Left_X=$Ax; }
   else { $Left_X=$Dx; }
   if($Ay < $By){ $High_Y=$Ay; }
   else { $High_Y=$By; }
   
   $block_X=$result[14];
   $block_Y=$result[15];
   
   $Bl_Ax = ($Left_X - $ImgLeftPoint) ;
   $Bl_Ay = ($High_Y - $ImgHigherPointModif);
   
   $block_path= get_blockpath($db, $id_block, $originfile);
   $original=imagecreatefrompng($block_path);
   
   imagecopy( $img, $original, $Bl_Ax, $Bl_Ay, 0, 0, $block_X, $block_Y);
   }
   
   if($user)
   {
   $print_img='users/'.$user.'/tmp/art_'.$article_id.'.png';
   }
   else
   {
   $print_img=$tmp_nobody_dir.'art_'.$article_id.'.png';
   }
   
   imagepng($img, $print_img);  
        
   imagedestroy ($original);
   imagedestroy ($img);
   
     // zoom
   if($block_zoom_ratio)
   {
   $display_img_width_zoomed=(int)($img_W * $block_zoom_ratio / 100);
   $display_img_height_zoomed=(int)($img_H * $block_zoom_ratio / 100);
   }
   else if(!$block_zoom_ratio AND $zoom_ratio)
   {
   $display_img_width_zoomed=(int)($img_W * $zoom_ratio / 100);
   $display_img_height_zoomed=(int)($img_H * $zoom_ratio / 100);
   }
   else
   {
   $display_img_width_zoomed=$img_W;
   $display_img_height_zoomed=$img_H;
   }
   // affichage
   print '<IMG src="'.$print_img.'" alt="img '.$article_id.'" width="'.$display_img_width_zoomed.'" height="'.$display_img_height_zoomed.'" border="1">';
  }

?>
Return current item: Phpress