Example #1
0
 /**
  * Method render
  * @access public
  * @param boolean $ajax_render [default value: false]
  * @return mixed
  * @since 1.1.9
  */
 public function render($ajax_render = false)
 {
     $gallery_table = new Table();
     $gallery_table->setId("PhotoGalleryTable" . rand(0, 999999))->activatePagination();
     $header = new RowTable();
     for ($i = 0; $i < $this->nb_col; $i++) {
         $header->add();
     }
     $gallery_table->addRow($header->setHeaderClass(0));
     $ind = 0;
     $last_ind = -1;
     $gallery_row = null;
     $files = scandir($this->path, 1);
     for ($i = 0; $i < sizeof($files); $i++) {
         $file = $files[$i];
         if ($file != "." && $file != "..") {
             $getExt = explode(".", $file);
             $countExt = count($getExt);
             $fExt = $countExt - 1;
             $myExt = $getExt[$fExt];
             if ((is_dir($this->path . $file) || $this->in_arrayi($myExt, $this->picture_ext)) && $file != $this->thumbnail_folder) {
                 if ($ind != $last_ind && $ind % $this->nb_col == 0) {
                     if ($gallery_row != null) {
                         $gallery_table->addRow($gallery_row);
                     }
                     $gallery_row = new RowTable();
                     $gallery_row->setWidth("25%");
                     $last_ind = $ind;
                 }
                 if (is_dir($this->path . $file)) {
                     if ($this->subfolder) {
                         $folder_pic = new Picture($this->folder_pic, 128, 128, 0, Picture::ALIGN_ABSMIDDLE, $file);
                         $url = $this->getPage()->getCurrentURL();
                         if (($pos = find($url, "gallery_event=")) > 0) {
                             $pos2 = find($url, "&", 0, $pos);
                             if ($pos2 == 0) {
                                 $url = substr($url, 0, $pos - 1);
                             } else {
                                 $url1 = substr($url, 0, $pos - 1);
                                 $url2 = substr($url, $pos2, strlen($url));
                                 $url = $url1 . $url2;
                             }
                         }
                         if (find($url, "?") > 0) {
                             $url = $url . "&";
                         } else {
                             $url = $url . "?";
                         }
                         $url = $url . "gallery_event=" . urlencode(str_replace($this->original_path, "", $this->path . $file));
                         $folder_link = new Link($url, Link::TARGET_NONE, new Object($folder_pic, "<br/>", $file));
                         $gallery_row->add($folder_link);
                         $ind++;
                     }
                 } else {
                     if ($this->in_arrayi($myExt, $this->picture_ext)) {
                         $pic_file = str_replace(str_replace("\\", "/", realpath(SITE_DIRECTORY)) . "/", "", str_replace("\\", "/", realpath($this->path)) . "/" . $file);
                         $pic_file_lower_ext = str_replace("." . $myExt, strtolower("." . $myExt), $pic_file);
                         if ($pic_file_lower_ext != $pic_file) {
                             $path_file_lower_ext = str_replace($pic_file, $pic_file_lower_ext, str_replace("\\", "/", realpath(SITE_DIRECTORY . "/" . $pic_file)));
                             if (!rename(realpath(SITE_DIRECTORY . "/" . $pic_file), $path_file_lower_ext)) {
                                 $pic_file_lower_ext = $pic_file;
                             }
                         }
                         $pic_name = str_replace("." . $myExt, "", $file);
                         $pic_thumbnail = $pic_file_lower_ext;
                         if (trim($this->thumbnail_folder) != "") {
                             if (in_array(strtolower($myExt), array("jpg", "jpeg", "gif", "png"))) {
                                 if (!is_dir(realpath($this->path) . "/" . $this->thumbnail_folder)) {
                                     mkdir(realpath($this->path) . "/" . $this->thumbnail_folder);
                                 }
                                 $pic_thumbnail_path = realpath($this->path . "/" . $this->thumbnail_folder) . "/" . str_replace("." . $myExt, strtolower("." . $myExt), $file);
                                 $pic_thumbnail = str_replace(str_replace("\\", "/", realpath(SITE_DIRECTORY)) . "/", "", str_replace("\\", "/", realpath($this->path . "/" . $this->thumbnail_folder)) . "/" . str_replace("." . $myExt, strtolower("." . $myExt), $file));
                                 if (strtolower($myExt) == "gif") {
                                     // convert to jpg
                                     $pic_thumbnail_path = str_replace(".gif", ".jpg", $pic_thumbnail_path);
                                     $pic_thumbnail = str_replace(".gif", ".jpg", $pic_thumbnail);
                                 }
                                 if (!file_exists($pic_thumbnail_path)) {
                                     if (strtolower($myExt) == "jpg" || strtolower($myExt) == "jpeg") {
                                         jpegReductionFixe($pic_file_lower_ext, $pic_thumbnail_path, 128, 128);
                                     } else {
                                         if (strtolower($myExt) == "png") {
                                             pngReductionFixe($pic_file_lower_ext, $pic_thumbnail_path, 128, 128);
                                         } else {
                                             $tmp_file = realpath($this->path . "/" . $this->thumbnail_folder) . "/temp.jpg";
                                             gif2jpeg($pic_file_lower_ext, $tmp_file);
                                             jpegReductionFixe($tmp_file, $pic_thumbnail_path, 128, 128);
                                             unlink($tmp_file);
                                         }
                                     }
                                 }
                             }
                         }
                         $pic = new Picture($pic_thumbnail, 128, 128, 0, Picture::ALIGN_ABSMIDDLE, $pic_name);
                         $pic->addLightbox("Lightbox" . $gallery_table->getId(), $pic_file_lower_ext, "\$(window).width()-(\$(window).width()*0.2)", "\$(window).height()-(\$(window).height()*0.2)");
                         $gallery_row->add(new Object($pic, "<br/>", $pic_name));
                         $ind++;
                     }
                 }
             }
         }
     }
     if ($gallery_row != null) {
         while ($ind % $this->nb_col != 0) {
             $gallery_row->add();
             $ind++;
         }
         $gallery_table->addRow($gallery_row);
     }
     return $gallery_table->render($ajax_render);
 }
Example #2
0
function makePngIphoneIcon($InFile, $OutFile, $Width = 100, $Height = 100)
{
    $dim = getimagesize($InFile);
    $haut = $dim[1];
    $larg = $dim[0];
    if ($haut != 100 && $larg != 100) {
        pngReductionFixe($InFile, $OutFile, 100, 100, true);
        $InFile = $OutFile;
    }
    // Load the image where the logo will be embeded into
    $image = imagecreatefrompng($InFile);
    // Load the overlay image
    $overlayImage = imagecreatefrompng(dirname(__FILE__) . "/../img/mask_icon_iphone.png");
    //imagealphablending($overlayImage, true);
    // Get dimensions
    $imageWidth = imagesx($image);
    $imageHeight = imagesy($image);
    $overlayImageWidth = imagesx($overlayImage);
    $overlayImageHeight = imagesy($overlayImage);
    imagelayereffect($overlayImage, IMG_EFFECT_OVERLAY);
    // Paste the logo
    imagecopy($overlayImage, $image, ($overlayImageWidth - $imageWidth) / 2, ($overlayImageHeight - $imageHeight) / 2, 0, 0, $imageWidth, $imageHeight);
    if ($Width != 100 && $Height != 100) {
        $diffHeight = 0;
        $diffWidth = 0;
        if ($imageWidth > $imageHeight) {
            $reduire = $Width / $imageWidth;
            $larg2 = $Width;
            $haut2 = round($imageHeight * $reduire);
            $diffHeight = ($Height - $haut2) / 2;
        } else {
            $reduire = $Height / $imageHeight;
            $larg2 = round($imageWidth * $reduire);
            $haut2 = $Height;
            $diffWidth = ($Width - $larg2) / 2;
        }
        ImageCopyreSampled($overlayImage, $overlayImage, $diffWidth, $diffHeight, 0, 0, $larg2, $haut2, $imageWidth, $imageHeight);
    }
    if (file_exists($OutFile)) {
        unlink($OutFile);
    }
    touch($OutFile);
    imagepng($overlayImage, $OutFile);
    // Release memory
    imageDestroy($image);
    imageDestroy($overlayImage);
    makePngColorTransparentBackground($OutFile, $OutFile, array('red' => 255, 'green' => 0, 'blue' => 255));
}