Author Topic: blur effect on thumbnails (v@no)  (Read 46742 times)

0 Members and 1 Guest are viewing this topic.

Offline BartAfterDark

  • Hero Member
  • *****
  • Posts: 520
    • View Profile
blur effect on thumbnails (v@no)
« on: January 15, 2006, 12:19:09 AM »
Hello.
I just saw that V@NO added a blur effect to the thumbnails users do not have access to :)
How can this be done :mrgreen:

  - lars

Offline dosensteck

  • Full Member
  • ***
  • Posts: 160
    • View Profile
Re: blur effect on thumbnails (v@no)
« Reply #1 on: January 15, 2006, 05:51:43 PM »
yep, its a nice feature :)

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: blur effect on thumbnails (v@no)
« Reply #2 on: January 15, 2006, 06:10:57 PM »
If you look where these thumbnails located, you'd see that they are in a sub-folder from "normal" thumbnails.

If uploading two sets of thumbnails is ok for you, you can try to find in includes/functions.php
Code: [Select]
      $file_src = get_file_path($thumb_file_name, "thumb", $cat_id, 0, 1);insert below:
Code: [Select]
      if (!$show_link)
      {
        $file_src_new = str_replace("/".$thumb_file_name, "/blur/".$thumb_file_name, $file_src);
        if (file_exists($file_src_new)) $file_src = $file_src_new;
      }

The blur thumbnails must be placed in data/thumbnails/XX/blur/[/color] folder
If no "blur" thumbnail found, the "normal" thumbnail will be used instead.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline BartAfterDark

  • Hero Member
  • *****
  • Posts: 520
    • View Profile
Re: blur effect on thumbnails (v@no)
« Reply #3 on: January 15, 2006, 06:54:44 PM »
aha ;)
Would be great if GDlib could blur it for us.
(I found this http://www.macx.de/essays/gdlib/bildfilter.html ) But it's php5 only :/

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: blur effect on thumbnails (v@no)
« Reply #4 on: January 15, 2006, 07:03:40 PM »
Well, tell you the truth, what you see on my site is generated on-fly by GD ;)
here is a code simular to what I'm using (note, GD v2 and PHP v5.x is required for this!):
create file thumb.php with this content:
Code: [Select]
<?php
error_reporting
(E_ALL);
$effects = array(
  "blur" => array("101"10),
  "grey" => array("010"),
  "contrast" => array("001"0, -50),
);
$etag "";
$modified "";
$folder "";
define("ROOT_PATH""./");
include(
"config.php");
include(
ROOT_PATH."includes/constants.php");
if(!
function_exists('file_get_contents'))
{
  function file_get_contents($file)
  {
    $file file($file);
    return !$file false implode(''$file);
  }
}

if (isset(
$_GET['file']) && !empty($_GET['file']))
{
  $file THUMB_DIR."/".urldecode($_GET['file']);
  if (isset($_GET['folder'])) $folder $_GET['folder'];
  function effect($file$data$array = array())
  {
    $types = array(=> "gif"=> "jpeg"=> "png");
    $type getimagesize($file);
    $type = @$types[$type[2]];
    if (empty($type) || !$image = @ImageCreateFromString($data)) return false;
    $effect = (isset($array[0])) ? $array[0] : "000";
    $l = (isset($array[1])) ? $array[1] : 10;
    $param = (isset($array[2])) ? $array[2] : -50;
    if (substr($effect01) == "1")
    {
      for ($i 0$i $l$i++)
      {
        imagefilter($imageIMG_FILTER_GAUSSIAN_BLUR);
      }
    }
    if (substr($effect11) == "1")
    {
      imagefilter($imageIMG_FILTER_GRAYSCALE);
    }
    if (substr($effect21) == "1")
    {
      imagefilter($imageIMG_FILTER_CONTRAST$param);
    }    
    ob_start
();
    $cr "Image".$type;
    @$cr($image''85);
    $data ob_get_contents();
    ob_end_clean();
    return $data;
  }
  if (file_exists($file) && in_array($folderarray_keys($effects)))
  {
    $etag =  crc32($file.$folder);
    $info = @getimagesize($file);
    if (!isset($info['mime']) || !$info['mime'])
    {
      $ext strtolower(substr(strchr($file,"."), 1));
      include(ROO_PATH."includes/upload_definitions.php");
      if (isset($mime_type_match[$ext]))
      {
        $mime $mime_type_match[$ext][0];
      }
    }
    else
    {
      $mime $info['mime'];
    }
    $modified = ($modified) ? $modified gmdate('D, d M Y H:i:s'filemtime($file)).' GMT';
    if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && ($_SERVER['HTTP_IF_MODIFIED_SINCE'] == $modified || substr($_SERVER['HTTP_IF_MODIFIED_SINCE'],0,(strlen($_SERVER['HTTP_IF_MODIFIED_SINCE'])-strlen(strrchr($_SERVER['HTTP_IF_MODIFIED_SINCE'],";")))) == $modified) && (!isset($_SERVER['HTTP_IF_NONE_MATCH']) || empty($_SERVER['HTTP_IF_NONE_MATCH']) || $_SERVER['HTTP_IF_NONE_MATCH'] == '"'.$etag.'"'))
    {
      header("HTTP/1.1 304 Not Modified");
      header("ETag: \"".$etag."\"");
      exit;
    }
    $data "";
    $data effect($filefile_get_contents($file), $effects[$folder]);
    if ($data)
    {
      header("Last-Modified: " $modified);
      header("Content-type: ".$mime);
      header("ETag: \"".$etag."\"");
      echo $data;
      exit;
    }
  }
}
header("HTTP/1.1 404 Not Found");
/*
header("Content-type: image/gif");
header("Content-length: 208");
$file = "R0lGODlhIAAgAKIAAO/v71lZWcDAwP8AAPHx7v///////wAAACH5BAEAAAYALAAAAAAgACAAAAOVKLrc/osIQ6u9OFOpu6/cJ2LhaBrlKaaqx7baSwF0bddBPGVA4f/AgiCXkRl6weBQp0Emf8viDuN8Comk6cU5GPi6vmi2CeyCw9iLsVo4o5m8shmatqx/57NYrbWwk3t2fRV/SnUggzNWdHBUi29STRAMhxuJBgGZmpubjTAdRp+Ioi6XpCimpKGqqaIEr7CxsrO0sgkAOw==";
echo base64_decode($file);
*/
exit;
?>
Upload it to your 4images root directory.

If you dont have apache webserver or mod_rewrite is not installed/enabled, then skip this step and continue with next, otherwise create data/thumbnails/.htaccess file with the following content:
Code: [Select]
RewriteEngine on
RewriteRule ^([0-9]+/)([a-zA-Z0-9]+)/(.*)$ ../../thumb.php?file=$1$3&folder=$2


If you want to show blur thumbnails for the images visitor not allow to view, in includes/functions.php find:
Code: [Select]
      $file_src = get_file_path($thumb_file_name, "thumb", $cat_id, 0, 1);If you have apache webserver with mod_rewrite enabled then insert below:
Code: [Select]
      if (!$show_link)
      {
        $file_src = str_replace("/".$thumb_file_name, "/blur/".$thumb_file_name, $file_src);
        if (file_exists($file_src_new)) $file_src = $file_src_new;
      }
Otherwise insert below this:
Code: [Select]
      if (!$show_link)
      {
        $file_src = "thumb.php?file=".urlencode(str_replace(THUMB_DIR."/", "", $file_src))."&folder=blur";
      }

Done.


In thumb.php I've added three "effects":
1) blur
2) greyscale
3) enhanced contrast
the 1) and 3) effects are used together when accessed "blur" images.
You also can get the 2) effect if you replace word "blur" in the url to "grey" and to get 3) effect use "contrast"

These effects being controled by third parameter of  effect() functions.
The parameter represent an array, the first item in the array represent the type of effect and must contein three digits string (i.e. 101), the sequence of the digits is equal to the effect list above. Its almost like a binary code: "1" is equal to turn on filter, "0" - turn off
For example if you want only blur effect use "100", for only grey effect: "010" and for grey effect with contrast enhencment: "011"


Also, this code is checking "last modifyed" headers, same as normal webserver does, so if file was not modifyed, it will return only "304 not modifyed" header and will not recreate thumbnail, which will save some perfomance and bandwidth.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline BartAfterDark

  • Hero Member
  • *****
  • Posts: 520
    • View Profile
Re: blur effect on thumbnails (v@no)
« Reply #5 on: January 15, 2006, 07:22:41 PM »
great :D
I tried to replace
Code: [Select]
    $file_src = get_file_path($thumb_file_name, "thumb", $cat_id, 0, 1);But I gives me an error
Code: [Select]
Parse error: syntax error, unexpected ';' in W:\www\includes\functions.php on line 369and that line is this
Code: [Select]
            if (!$show_link && get_file_path("blur/".$thumb_file_name, "thumb", $cat_id, 0, 0); :/

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: blur effect on thumbnails (v@no)
« Reply #6 on: January 15, 2006, 07:38:10 PM »
Oh, missed ) at the end. (the reply above fixed now)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline BartAfterDark

  • Hero Member
  • *****
  • Posts: 520
    • View Profile
Re: blur effect on thumbnails (v@no)
« Reply #7 on: January 15, 2006, 09:28:05 PM »
I get this now :(
Code: [Select]
Parse error: syntax error, unexpected T_ELSE in W:\www\includes\functions.php on line 373line 373 is
Code: [Select]
    else  {I read somewhere it's because to many else are being used

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: blur effect on thumbnails (v@no)
« Reply #8 on: January 15, 2006, 10:10:11 PM »
Strange...worked just fine for me...

Also, just realized, that the method with GD will not work with the method physicaly uploading blur thumbnails as I mentioned in my first reply.
I've updated the post with thumb.php with instructions on what needs to be changed in includes/functions.php
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline BartAfterDark

  • Hero Member
  • *****
  • Posts: 520
    • View Profile
Re: blur effect on thumbnails (v@no)
« Reply #9 on: January 15, 2006, 10:42:21 PM »
Great. Got first part working. Now how do I run thumb.php so it can convert and copy the images? :)

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: blur effect on thumbnails (v@no)
« Reply #10 on: January 15, 2006, 10:52:24 PM »
This is all explained in the post with thumb.php
If you dont have apache webserver with mod_rewrite enabled, this will not work for you...sorry.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline BartAfterDark

  • Hero Member
  • *****
  • Posts: 520
    • View Profile
Re: blur effect on thumbnails (v@no)
« Reply #11 on: January 15, 2006, 10:58:33 PM »
uhm still got quite understand it
But what should the url look like. If I want to run make some pictures?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: blur effect on thumbnails (v@no)
« Reply #12 on: January 15, 2006, 11:04:51 PM »
If you did everything right, you should not worry about the url, it will automaticaly create the needed url for you.
Anyways, with apache and mo_rewrite the url should looks like this:
data/thumbnails/XX/blur/image_name.jpg
mod_rewrite will automaticaly change that url to:
thumb.php?file=data/thumbnails/XX/image_name.jpg&folder=blur

the url query file should contein correct path to the image and query folder should contein the name of the effect (blur, grey or contrast)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline ch€ri{Bi}²

  • Sr. Member
  • ****
  • Posts: 315
  • A PRoBLeM wIthOUt SoLuTioN Is NoT rEAllY a PRoBLeM
    • View Profile
    • Pat's Gallery
Re: blur effect on thumbnails (v@no)
« Reply #13 on: January 16, 2006, 04:18:18 PM »
 8O OMG  8O , i started working on these effects (using GD) on thumbs two months ago...
and i stopped because in my results, i got time-out problems (when displaying many thumbs) and thumbnails quality  :?
then I preferred to use a basic method:  CSS style effects... :roll:

 :?:  what is the consequence of this modification on the display speed and the server load ?
is there somebody who measured it? or there is somebody who noticed a change in the behavior of his gallery?
ch€ri{Bi}²


Offline BartAfterDark

  • Hero Member
  • *****
  • Posts: 520
    • View Profile
Re: blur effect on thumbnails (v@no)
« Reply #14 on: January 16, 2006, 05:41:18 PM »
not working with php4 :'(
Code: [Select]
Fatal error: Call to undefined function: imagefilter() in /home/brandk/public_html/4images/thumb.php on line 40