Yii 1.1: google-image-search

Get images by given query from "Google Image Search API JSON interface"

Google Image search (yii extension)

This extension use "Google Image Search API JSON interface" https://developers.google.com/image-search/v1/jsondevguide

Limitations by service

  • Max results per page: 8
  • Max pages: 8

This means you can not get more than 8 pages by one given query string. BUT you can change some of the url params and get different results.

One example is to change image type [png|jpg|gif|bmp] (but not search word) so you can get 4 times more results querying like this. Start with 8 pages of png, and continue with other types. In result you get 32 pages and every page with 8 results.


  • cURL

Extension includes

  • GoogleImageSearch (CComponent) - it can be used alone with your code
  • ImageSearchController (CExtController) - Example of component use
  • views/search.php - html/js/css view for ImageSearchController (jQuery required)

How to use

You can use it in two ways.

  1. Based on given example
  2. Write your own controller/view

But both ways need same init configuration:

    // Google image search component
         //'cacheSec' => 3600, //default 1week

1. With given example

For given example you need to add configuration to your controllerMap:

        //'layout' => '//layouts/layout', //default: layouts/main

Now you can access example by adding /imgSearch/search to your base url (Result: http://my-domain.lc/imgSearch/search)

2. Write your own controller/view

You can use GoogleImageSearch component and use it where you want in you code. Here is a quick example:

        $imgSearch = Yii::app()->imgSearch;
        // All possible params:
        // https://developers.google.com/image-search/v1/jsondevguide#json_args
            'rsz' => 4, //default: 8
            //'as_filetype' => 'png', //default to all types
        // OR set params one by one
        $jsonRaw = $imgSearch->getResults( $searchString );
        $json = json_decode( $jsonRaw );

Available params


About & More

Project at bitbucket: https://bitbucket.org/briiC/googleimagesearch.yii.ext


Search formSearch results

Total 4 comments

#13142 report it
briiC.lv at 2013/05/07 03:33pm

Hi! You have to get some error of this 1) Try check javascript error (http://webmasters.stackexchange.com/questions/8525/how-to-open-the-javascript-console-in-different-browsers)

2) If there is nothing try to find errors in Yii protected/runtime/application.log or in apache error.log

I think there could be error with different url path rules.

#13138 report it
stromgol at 2013/05/07 10:49am
Search doesn't give any result

I successfully installed the extension but when I enter a search criteria, using the given exemple view, I only get a message "loading" in the result box. I also installed the curl extension...

#12734 report it
briiC.lv at 2013/04/09 03:08am
Thanks for comment!

At the beginning there was only component that i wrote, and after that i thought i need to write example controller for this (to start easily). Controller and View should be considered as example and can be edited as you want.

Look at controllers/views/search.php:150

$(document).on("click", "#googleImageSearch .search-results img", function(){
    var $img = $(this);
    var originalUrl = decodeURI( $img.attr("alt") );
    // download on click
    // or open 
    // write your code..

you can change it.

For better use create new actions and view in your core project and use Yii::app()->imgSearch as I used in ImageSearchController. This will give you freedom.

Thanks for feedback!

#12733 report it
ApXaHgheJI at 2013/04/09 02:45am

Hi, its a nice module, I think its will be the best if on hover image, I can add and download image right in project, to easy use it's everywhere.

But for the moment, its good ext. ! A+

Leave a comment

Please to leave your comment.

Create extension