CodeIgniter Forums

Full Version: Thumbnail help with GalleryCMS
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]cjames[/eluser]
I am using GalleryCms that is based of codeigniter. Currently the cms has values for height and width and it sizes the thumbnails to the longest edge. I am wanting to get the thumbnails cropped square. Any ideas? I'm not much of a coder so it has been guessing for me.

There are two places I see thumbnail stuff:
Image.php has this:

Code:
// Create thumbnail
          $config['image_library']   = 'gd2';
          $config['source_image']    = './uploads/' . $upload_info['file_name'];
          $config['create_thumb']    = TRUE;
          $config['maintain_ratio']  = TRUE;
          $config['width']           = $album_config->thumb_width;
          $config['height']          = $album_config->thumb_height;
          // TODO Handle cropping.

          $this->load->library('image_lib', $config);

          $this->image_lib->resize();
          $this->image_lib->clear();

and album.php has this:

Code:
// Update all album's thumbnails
        $images = $this->image_model->get_images_by_album_id($album_id);
        if ( ! empty($images))
        {
          $this->load->library('image_lib');
          $config = array();
          foreach ($images as $image)
          {
            $config['image_library']   = 'gd2';
            $config['source_image']    = './uploads/' . $image->file_name;
            $config['create_thumb']    = TRUE;
            $config['maintain_ratio']  = TRUE;
            $config['width']           = $this->input->post('thumb_width');
            $config['height']          = $this->input->post('thumb_height');
            $config['thumb_marker']    = '_thumb';
            // TODO Handle cropping
            $this->image_lib->initialize($config);
            $this->image_lib->resize();
            $this->image_lib->clear();
            $config = array();
          }
        }
        
        $now = date('Y-m-d H:i:s');
        $this->album_model->update(array('updated_at' => $now), $album_id);
        
        redirect("album/images/$album_id");
        return;
      }
    }

El Forum

[eluser]recon[/eluser]
Code:
// Create thumbnail
          $config['image_library']   = 'gd2';
          $config['source_image']    = './uploads/' . $upload_info['file_name'];
          $config['create_thumb']    = TRUE;
          $config['maintain_ratio']  = TRUE;
          $config['width']           = max( $album_config->thumb_width, $album_config->thumb_height );
          $config['height']          = max( $album_config->thumb_width, $album_config->thumb_height );
          // TODO Handle cropping.


should give you a square image equal to the largest edge of source image.

El Forum

[eluser]cjames[/eluser]
@recon Thanks for your reply. I put the code into the images.php and still no luck. Any other thoughts?

El Forum

[eluser]recon[/eluser]
looking at it a bit more $album_config->thumb_width; and $album_config->thumb_height are config setting, you need to change the setting in the config file to get the changes everywhere. the image size won't matter if the page that displayes them uses the config setting for height and width.

also try

$config['maintain_ratio'] = FALSE;

or

$this->image_lib->crop();

El Forum

[eluser]cjames[/eluser]
Still no luck. But I found this line in the album/config.php

Code:
?>
<?php /* Holding off on this one until next release.
<div class="alert alert-info">This forces the thumbnail to be crop to fit the exact dimensions.</div>
&lt;?php
echo form_label('Crop Thumbnails?', 'crop_thumbnails');
echo form_checkbox('crop_thumbnails', '1', $config->crop_thumbnails);
?&gt;
*
*/ ?&gt;

see it here:

https://github.com/bensonarts/GalleryCMS...config.php

El Forum

[eluser]recon[/eluser]
Well reading the comments it looks like this feature has not been implemented,

&lt;?php /* Holding off on this one until next release.

and

// TODO Handle cropping

The size of the images when shown on screen depend a several different factors, the main one being the <img /> tag or the CSS settings for that class or element id. But the system has several steps and any one of them could be the place where the resizing of the images is stopped.

I have a feeling that the images are not resized at all, and all that is happening is that he is changing the CSS values for the images when the pages are served.


you could try just making a script that resizes all the images in your servers image folder. probably be the easiest workaround.

Short of installing the gallery app myself I dont have any better suggestions.

here is an example i looked up quickly
http://www.saaraan.com/2012/07/resize-mu...-using-php , no idea if it will work for you though.