PLEASE NOTE: This article may be out-of-date. Please visit the Support site for the latest information.

STW API (v1.0 PHP4) Sample Code

6 posts / 0 new
Último envío
Imagen de puravida
puravida
Jedi Warrior
Conectado
Integró: 09/01/2007
Visitar puravida's Sitio web

I thought it might help to put all code in one place, so I'm putting a copy of the sample API code here as well.

Purpose: This code allows you to call thumbnails automatically without having to load a web page to initiate. It also allows for more advanced functionality -such as caching thumbnails on-the-fly to your server or manipulating the images once retrieved.

Prerequisites:

    Back-End API - PHP4 installed with GD 1.8 or later compiled
    Front-End (In-page) - PHP4 installed

Usage: Remember to change the [key_id] and [key] values in the URL to your access key ID and secret key, respectively. These can be found when you first login (in the lobby).

Check out the latest sample codes and plugins on our plugins page:
ShrinkTheWeb Site Preview Plugins

Imagen de puravida
puravida
Jedi Warrior
Conectado
Integró: 09/01/2007
Visitar puravida's Sitio web

It just occurred to me when I posted the code sample above that users using the API have the ability to manipulate the images once they've been retrieved. This will take some PHP skill and I don't have to write the code in just yet. In the meantime, here's some pointers in the right direction for those who cannot wait and have some experience:

Take the sample code above and then use the Simple Image Thumbnail Code to resize the image on-the-fly (best place is just before caching). That way, when you call it in your pages, there is no processor time to re-size then... only on writing the image during the initial caching.

This is very cool! Although this will allow users to get around needing to upgrade to PRO just for custom-sizes, I think it is something that can benefit a lot of users and many people will still upgrade to avoid having to mess with the code in the first place.

However, if someone wants to release a modified version of my sample code and include the custom re-size, that would be fantastic! *hint hint* Wink

-Brandon

Anonymous

I just did a custom integration using the sample code provided as a reference. I think you may suffer from the same bug I inherited..

You set $exists to $matches[1], and you then use it in a comparison wither it evaluates to true. It will always evaluate to true because it contains the literal string "true" or "false".

You want to set $exists = $matches[1] != "false", or something similar..

Imagen de puravida
puravida
Jedi Warrior
Conectado
Integró: 09/01/2007
Visitar puravida's Sitio web
koaladir wrote:
You want to set $exists = $matches[1] != "false", or something similar..

Hello, koaladir.

Not to be argumentative, but this code has been working. That comparison should never be run if the connection cannot be made, so the always "true" shouldn't matter. However, if a connection is made, we specifically return either a "true" or a "false", which will give the necessary condition.

If you are seeing that the code doesn't work for you, please do post your implementation and the results and I would be happy to take a look.

Best regards,

Brandon

Anonymous

This only took us a few minutes to get the call processing right for us to replace our Alexa, and so far this service has worked very well. The processing time for a new site is extremely quick. Although Alexa will queue new thumbnail requests, it can take hours or days for it to appear. An automatic trim function to limit the border might be nice for some sites like: http://www.lemon.uk.com/

I see in your snippet function you test for the literal value only when caching. You still have a race condition that will probably only affect the first couple views since until the thumbnail truly exists all remote references to the jpg file will result in a 404 until the images has been processed .. but i guess it still works for you.

I don't understand why you would be making the remote request for every viewing of the thumbnail vs checking for the cached image first? The setup/tear-down of the connections can add up quick when showing a page with multiple thumbnails, and even if caching is enabled, the calling function has to contain the same logic to determine the cached path and url display, so most who cache probably rewrite it all anyhow.

There are probably a number of people who can't read php and will be dropping this in verbatim and tweaking variables to make it work .. how many will leave the connect latency check in that makes unnecessary connections to your servers? There is no explicit close, so the connection to your servers stays open until their page finishes processing. Apache/RedHat can soak up a ton, but why keep double the threads/processes tied up?

Not to be argumentative at all, but the sample code helped establish the acceptable call parameters, but is a bit of a hack beyond that, and should be written to promote not only decent design, but efficient use of resources .. imho.

Just my 2 cents, we are all set, thanks for running this service.

Imagen de puravida
puravida
Jedi Warrior
Conectado
Integró: 09/01/2007
Visitar puravida's Sitio web
koaladir wrote:
I see in your snippet function you test for the literal value only when caching. You still have a race condition that will probably only affect the first couple views since until the thumbnail truly exists all remote references to the jpg file will result in a 404 until the images has been processed .. but i guess it still works for you.

I don't understand why you would be making the remote request for every viewing of the thumbnail vs checking for the cached image first? The setup/tear-down of the connections can add up quick when showing a page with multiple thumbnails, and even if caching is enabled, the calling function has to contain the same logic to determine the cached path and url display, so most who cache probably rewrite it all anyhow.

Ah, I see. That is very well possible.

I will take a look more in-depth. Admittedly, that code was written very quickly, so it could potentially use an overhaul.

If you have an update that you would like to share, please feel free to post it and you may place a recognition link for credit that you wrote it. Just post it in the plugins area with an appropriate title, so that people can find it. I will review that code as well and make sure it fits well. If so, then I will announce the updated sample code to those who cache locally and give you credit then as well.

Otherwise, I will take a look at our sample, as time permits.

Thank you for using our service and I'm glad you enjoy it so far.

Best regards,

Brandon

Topic locked

ShrinkTheWeb® (Sobre STW) es otra innovación de Neosys Consulting

Contáctenos | PagePix Benefits | Learn More | Nuestros socios | Política de privacidad | Términos de uso

©2014 ShrinkTheWeb. All rights reserved. ShrinkTheWeb is a registered trademark of ShrinkTheWeb.