Jump to content

Dribbble Module


Recommended Posts

I recently created a Dribbble API wrapper module (I am pretty new at creating modules) and wanted to know if its possible to use the $image API to retrieve the external Dribbble "shot" (image), resize it and store them along with the XML in the asset cache. That way I can load an image locally via the cached file(s) for the module instead of hitting Dribbble every time for the full size images. Any thoughts on how to best do this? Here is the current state of the module on Github: https://github.com/ryanscherler/ProcessDribbble

  • Like 4
Link to comment
Share on other sites

wanted to know if its possible to use the $image API to retrieve the external Dribbble "shot" (image), resize it and store them along with the XML in the asset cache. That way I can load an image locally via the cached file(s) for the module instead of hitting Dribbble every time for the full size images.

1) you may do this by using a hidden tools page with an images field and than you only have to use $page->images->add($shotImageUrl) to save the image to the tools page assets directory. And you have it as PageImage and you can do all image api stuff

2) I have uploaded a new module for Image Manipulation. With this you are able to use some well known image methods (width, height, size) and you can store the image together with your xml or json file instead of creating and using a tools page with InputFieldtypeImage.

Example (this could be somewhere in your makeRequest method):

// get your image from dribble and save it to your cache directory
$shotImageUrl = 'http://dribble.com/some/path/to/image.jpg';
$imgCacheFile = $this->cachePath . md5($url) . '.image.jpg'; 

$result = file_put_contents($imgCacheFile, file_get_contents($shotImageUrl));
// if $result is not false and greater than zero the image was successfully saved,

// now you can load the $imgCacheFile into the ImageManipulator, resize it and save it by overwriting the $imgCacheFile
$boolResult = wire('modules')->get('PageImageManipulator')->imLoad($imgCacheFile)->resize(360)->save();

// thats all 

PS: if you want rely on the PageImageManipulator module, you can set it as needed dependency for your module:

public static function getModuleInfo() {
   return array(
// ...
        'requires' => array('PageImageManipulator'),
    );
}

see: http://processwire.com/talk/topic/778-module-dependencies/

Edited by horst
  • Like 6
Link to comment
Share on other sites

Ryan, glad to see you working on this module! It looks like you already figured this out, but /site/assets/cache/[your dir] is usually a good place to store things like XML cache files. If connected with a page, then just use the page's files dir ($page->filesManager->path or $page->[your files field]->path). Horst is right that you can add files to pages and manipulate them using PW's methods from there. He's also written an excellent manipulation module. If you just need to resize images, also look into PW's ImageSizer class, which is ready to operate on any file (doesn't need to be connected to a page). In the dev branch, I'm about to push some updates to that class from Horst that add sharpening and auto rotation among other tweaks. Lastly, I wanted to mention that the dev branch also has the WireHttp class, which you may find more convenient than CURL. 

  • Like 3
Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...