Author Topic: [TIP/HACK] Square thumbnails for Gallery  (Read 9366 times)

0 Members and 1 Guest are viewing this topic.

Offline Flyershop

Re: [TIP/HACK] Square thumbnails for Gallery
« Reply #10 on: 27. May 2010, 08:44:57 »
My Dear Fellow Canadian,
Sucking up in the beginning of a reply is always a good thing to do i hear.  :D
I have finally mastered the art of cloning, only took me 4 weeks. I learn VERY QUICK!
I thought hey lets make all the images (in my clone i use first gallery image in my v-card) the same size.
That would look really cool i thought. Two weeks later here i am. I think what you did is what i am looking for.
I downloaded the zip, made the css entry. lord and behold! ... nope white screen. Oh yes my cloning skills will come in handy i thought. Changed every goddarn sobi and sobi2's into "sobitwo" (my clone name, original eh?)
and lord and behold ANOTHER white screen! If your work does what i need please send me in the right direction, if your work does not do what i need PLEASE tell me so i don't go crazy!

And if you have too much time to spare - sobitwo is the clone name, just make a special file for me. :D
I must be pushing it now huh?  :whistling:
Thank you so much for your time.
« Last Edit: 27. May 2010, 08:50:00 by Flyershop »
Country: Canada Canada |  OS: Windows Vista/Server 2008 Windows Vista/Server 2008 |  Browser: Firefox 3.6.3 Firefox 3.6.3 | View Profile

Offline Greg Hunt

  • Quality & Testing
  • Sobi Hero
  • *
  • Posts: 1069
  • Reviews:

    What is it?

Re: [TIP/HACK] Square thumbnails for Gallery
« Reply #11 on: 28. May 2010, 15:22:26 »
This hack was for an old version of the plugin, so you are wiping out all of the updates.

Relevant changes are as follows:
Replace the existing function sobi_gallery_resampleImage with the following:

Code: [Select]
   function sobi_gallery_resampleImage($file, $thumb, $fileType) {
           $config =& sobi2Config::getInstance();
           if($thumb) {
            $width = $this->thmW;
            $height = $this->thmH;
            $resize = $this->alwaysResizeThumb;
        }
        else {
            $width = $this->imgW;
            $height = $this->imgH;
            $resize = $this->alwaysResizeImages;
        }
        list($width_orig, $height_orig, $imgType) = getimagesize($file);
        if(!$resize && (($width_orig < $width) && ($height_orig < $height)))
        {
            return true;
        }
        $ratio_orig = $width_orig/$height_orig;

If ($thumb){
        if ($width/$height < $ratio_orig)
        {
            $width = $height*$ratio_orig;
        }
        else
        {
            $height = $width/$ratio_orig;
        }
} else {
        if ($width/$height > $ratio_orig)
        {
            $width = $height*$ratio_orig;
        }
        else
        {
            $height = $width/$ratio_orig;
        }
}
        switch($imgType) {
            case 1:
                if(!($image_p = imagecreatetruecolor($width, $height)))
                    return false;
                if(!($image = imagecreatefromgif($file)))
                    return false;
                if(!(imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig)))
                    return false;
                if(!(imagegif($image_p, $file)))
                    return false;
            break;
            case 2:
                if(!($image_p = imagecreatetruecolor($width, $height)))
                    return false;
                if(!($image = imagecreatefromjpeg($file)))
                    return false;
                if(!(imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig)))
                    return false;
                if(!(imagejpeg($image_p, $file,$config->key( "general", "jpeg_image_quality", 75 ))))
                    return false;
            break;
            case 3:
                if(!($image_p = imagecreatetruecolor($width, $height)))
                    return false;
                if(!($image = imagecreatefrompng($file)))
                    return false;
                if(!(imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig)))
                    return false;
                if(!(imagepng($image_p, $file,$config->key( "general", "png_image_compression", 0 ))))
                    return false;
            break;
        }
        imagedestroy($image_p);
        imagedestroy($image);
        return true;
   }

For a sobitwo clone it should be (i just did a manual once over so I might have missed one ot two):

Code: [Select]
   function sobitwo_gallery_resampleImage($file, $thumb, $fileType) {
             $config =& sobitwoConfig::getInstance();
             if($thumb) {
              $width = $this->thmW;
              $height = $this->thmH;
              $resize = $this->alwaysResizeThumb;
          }
          else {
              $width = $this->imgW;
              $height = $this->imgH;
              $resize = $this->alwaysResizeImages;
          }
          list($width_orig, $height_orig, $imgType) = getimagesize($file);
          if(!$resize && (($width_orig < $width) &&   ($height_orig < $height)))
          {
              return true;
          }
          $ratio_orig = $width_orig/$height_orig;
 
  If ($thumb){
          if ($width/$height < $ratio_orig)
          {
              $width = $height*$ratio_orig;
          }
          else
          {
              $height = $width/$ratio_orig;
          }
  } else {
          if ($width/$height > $ratio_orig)
          {
              $width = $height*$ratio_orig;
          }
          else
          {
              $height = $width/$ratio_orig;
          }
  }
          switch($imgType) {
              case 1:
                  if(!($image_p = imagecreatetruecolor($width, $height)))
                      return false;
                  if(!($image = imagecreatefromgif($file)))
                      return false;
                  if(!(imagecopyresampled($image_p, $image, 0, 0, 0, 0,   $width, $height, $width_orig, $height_orig)))
                      return false;
                  if(!(imagegif($image_p, $file)))
                      return false;
              break;
              case 2:
                  if(!($image_p = imagecreatetruecolor($width, $height)))
                      return false;
                  if(!($image = imagecreatefromjpeg($file)))
                      return false;
                  if(!(imagecopyresampled($image_p, $image, 0, 0, 0, 0,   $width, $height, $width_orig, $height_orig)))
                      return false;
                  if(!(imagejpeg($image_p, $file,$config->key(   "general", "jpeg_image_quality", 75 ))))
                      return false;
              break;
              case 3:
                  if(!($image_p = imagecreatetruecolor($width, $height)))
                      return false;
                  if(!($image = imagecreatefrompng($file)))
                      return false;
                  if(!(imagecopyresampled($image_p, $image, 0, 0, 0, 0,   $width, $height, $width_orig, $height_orig)))
                      return false;
                  if(!(imagepng($image_p, $file,$config->key(   "general", "png_image_compression", 0 ))))
                      return false;
              break;
          }
          imagedestroy($image_p);
          imagedestroy($image);
          return true;
     }

Greg
Country: Canada Canada |  OS: Windows Vista/Server 2008 Windows Vista/Server 2008 |  Browser: Firefox 3.6.3 Firefox 3.6.3 | View Profile

Offline Flyershop

Re: [TIP/HACK] Square thumbnails for Gallery
« Reply #12 on: 29. May 2010, 09:25:24 »
Thanks for all the effort.
I installed a quick skin. used original code and added the css
css set to 120 x 80

it does not seem to be working.
http://www.kokobaba.com/index.php?option=com_sobi2&catid=2&Itemid=47

it would be so very kind if you could take a look.
thanks in advance
Country: Canada Canada |  OS: Windows Vista/Server 2008 Windows Vista/Server 2008 |  Browser: MS Internet Explorer 7.0 MS Internet Explorer 7.0 | View Profile

Offline Flyershop

Re: [TIP/HACK] Square thumbnails for Gallery
« Reply #13 on: 03. June 2010, 19:13:10 »
Dear Greg,
I don't know if you missed my response.
Original code wasn't working, any ideas what i am doing wrong?

p.s. thaks for all your effort
Country: Canada Canada |  OS: Windows Vista/Server 2008 Windows Vista/Server 2008 |  Browser: MS Internet Explorer 7.0 MS Internet Explorer 7.0 | View Profile

Offline Flyershop

Re: [TIP/HACK] Square thumbnails for Gallery
« Reply #14 on: 04. June 2010, 16:44:42 »
It is working and i thank you Sooooooooooo much.

just for all of you undeskilled people like ME, i could not get this module
to work because i was not making the image use the CSS in the template.

dumb but sooooooo true!
Country: Canada Canada |  OS: Windows Vista/Server 2008 Windows Vista/Server 2008 |  Browser: MS Internet Explorer 7.0 MS Internet Explorer 7.0 | View Profile

Offline QMedia

Re: [TIP/HACK] Square thumbnails for Gallery
« Reply #15 on: 18. August 2010, 12:00:48 »
Any idea if / how to apply this also to the icons in sobi2?  If I could get cropped instead of forcing them to resize using only css it would be an awesome improvement to the look and feel :D
Country: Norway Norway |  OS: Windows Vista/Server 2008 Windows Vista/Server 2008 |  Browser: Firefox 3.6.8 Firefox 3.6.8 | View Profile

Offline Greg Hunt

  • Quality & Testing
  • Sobi Hero
  • *
  • Posts: 1069
  • Reviews:

    What is it?

Re: [TIP/HACK] Square thumbnails for Gallery
« Reply #16 on: 18. August 2010, 12:30:24 »
You would likely need to hack the sobi2 core.  This was done mostly using CSS and the only real code change was reversing the way images were resized and let the CSS crop the rest. the the code change is usually changing a < to a > somewhere.

Greg
Country: Canada Canada |  OS: Windows 7/Server 2008 R2 Windows 7/Server 2008 R2 |  Browser: Firefox 3.6.6 Firefox 3.6.6 | View Profile

Offline QMedia

Re: [TIP/HACK] Square thumbnails for Gallery
« Reply #17 on: 18. August 2010, 12:54:14 »
Thanks for you quick reply :)

My php skills are somewhat limited to say the least..so sorry if I'm way off here :)

I've noticed in sobi2.class.php  there's a function:

Code: [Select]
function resampleImage( $file, $scope, $success )
Looks very similar to the same function handling the resizing of the thumbnails of the gallery plugin..wouldn't a similar change to this function work on the icons?

Or perhaps paste in a similar function which is referred to
Code: [Select]
if($scope == 'ico')     ? :)
« Last Edit: 18. August 2010, 14:13:45 by QMedia »
Country: Norway Norway |  OS: Windows Vista/Server 2008 Windows Vista/Server 2008 |  Browser: Firefox 3.6.8 Firefox 3.6.8 | View Profile

Offline rocco_h

  • Sobi Newbie
  • *
  • Posts: 17
Re: [TIP/HACK] Square thumbnails for Gallery
« Reply #18 on: 18. September 2010, 04:17:51 »
I tried your solution but it didn't work....I was trying to set the thumbnail image to 100px x 300px (portrait) in the css file but it doesn't take effect....anyone knows how to make the thumbnail image portrait to a specified size?? please let me know.
Country: Canada Canada |  OS: Windows 7/Server 2008 R2 Windows 7/Server 2008 R2 |  Browser: Firefox 3.6.10 Firefox 3.6.10 | View Profile

Online DJ J

Re: [TIP/HACK] Square thumbnails for Gallery
« Reply #19 on: 27. September 2010, 22:39:25 »
Thanks "urbanlives" for this nice hack. It works and looks great.
I'm wondering is it possible to display the same way the default image (<?php echo $img; ?>) in vcard template ???

Greetings,
DJ J
Joomla! - 1.5.25 | Sobi 2.9.4.1 | PHP - 5.2.17 | MySQL - 5.1.49 | Apache - 2.2.8 | Firefox 9.0.1 | IE 6.0 :)
Country: Poland Poland |  OS: Windows XP Windows XP |  Browser: Firefox 3.6.10 Firefox 3.6.10 | View Profile

Tags: