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.
Requirements ¶
- 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.
- Based on given example
- Write your own controller/view
But both ways need same init configuration:
<?php
//..
'components'=>array(
// Google image search component
'imgSearch'=>array(
'class'=>'application.extensions.googleImageSearch.GoogleImageSearch',
//'cacheSec' => 3600, //default 1week
),
)
//..
1. With given example ¶
For given example you need to add configuration to your controllerMap:
<?php
//..
'controllerMap'=>array(
'imgSearch'=>array(
'class'=>'application.extensions.googleImageSearch.controllers.ImageSearchController',
//'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:
<?php
$imgSearch = Yii::app()->imgSearch;
// All possible params:
// https://developers.google.com/image-search/v1/jsondevguide#json_args
$imgSearch->setParams(array(
'rsz' => 4, //default: 8
//'as_filetype' => 'png', //default to all types
));
// OR set params one by one
//$imgSearch->setParam('rsz',4);
//$imgSearch->setParam('as_filetype','png');
$jsonRaw = $imgSearch->getResults( $searchString );
$json = json_decode( $jsonRaw );
var_dump($json);
Available params ¶
https://developers.google.com/image-search/v1/jsondevguide#json_args
About & More ¶
Project at bitbucket: https://bitbucket.org/briiC/googleimagesearch.yii.ext
Screenshots ¶
Nice
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+
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
[javascript] $(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 inImageSearchController
. This will give you freedom.Thanks for feedback!
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...
@stromgol
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.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.