2

I am using CakePHP framework version 2.6.1.

I am creating a function which will get properties images and will create its thumbnail by phpThumb.

My issue is I am not able to create thumbnail from phpThumb in my function. I am getting all the data as I want. Here is my controller

I tried to load helper of phpThumb like this

public $helpers = array('PhpThumb.PhpThumb');

but didn't work for me. Then I tried to import it from my parent AppController likeApp::import('Helper', 'PhpThumb.PhpThumb');` but unfortunately it didn't work too.

I checked my error logs and found this error

PHP Fatal error: Call to a member function url() on a non-object in /home/gulfsothebysrealty/public_html/app/Controller/CronController.php on line 39

in $propertyImages['Photo']['image_url'] i am getting propspace server image url

How can I generate a thumbnail by using phpThumb in controller?

class CronController extends AppController {

public function index() {
    $properties = $this->Property->find( 'all', array(
            'conditions' => array(
                'Property.thumb_updated' => 0
            ),
            'limit'      => 5,
            'order'      => array( 'Property.id' => 'desc' )
        )
    );
    foreach ( $properties as $property ) {
        $propertyId = $property['Property']['id']; 
        $data = array( 'id' => $propertyId, 'thumb_updated' => 1 );
        $this->Property->save( $data );
        $getImages = $this->Property->Photo->find( 'all', array(
            'conditions' => array(
                'Photo.property_id' => $propertyId,
            ),
            'order'      => array( 'Photo.property_id' => 'desc' )
        ) );
        foreach ( $getImages as $propertyImages ) {
            if ( ! empty( $propertyImages['Photo']['image_url'] ) ) { 
/*line 39*/     $propertyImageThumb = $this->PhpThumb->url( $propertyImages['Photo']['image_url'], array(
                    'w'  => 1349,
                    'h'  => 500,
                    'zc' => 1
                ) );
                echo '<pre>';
                print_r( $propertyImageThumb );
                echo '</pre>';
            }

        }
      } 
    } 
   }
halfer
  • 19,824
  • 17
  • 99
  • 186
Owais Aslam
  • 1,577
  • 1
  • 17
  • 39
  • 2
    phpthumb is an ancient and terrible lib. Try Imagine, I wrote a cake plugin wrapper around it https://github.com/burzum/cakephp-imagine-plugin Also, the controller is the wrong place to do data manipulation. – floriank Jan 23 '17 at 14:42
  • the issue is i am working on a website which cakephp version is 2.6 and i have to use phpthumb i'll try your plugin on any new site. – Owais Aslam Jan 23 '17 at 14:53
  • @OwaisAslam - please select 2.x branch for implementation on cakephp 2 – justrohu Jan 24 '17 at 03:16
  • 2.x branch ?? @justrohu – Owais Aslam Jan 24 '17 at 06:15

1 Answers1

2

I got the solution guys,

I was doing a single mistake

i need to import phpThumb helper from AppController as i did

App::import( 'Helper', 'PhpThumb.PhpThumb' );

then i had to make an object for phpThumb Helper

$phpthumb = new PhpThumbHelper(new View());

After this now i am able to create thumbnail by using $phpThumb

$propertyImageThumb = $phpThumb->url( $propertyImages['Photo']['image_url'], array(
                'w'  => 1349,
                'h'  => 500,
                'zc' => 1
            ) );
Owais Aslam
  • 1,577
  • 1
  • 17
  • 39