A PHP5 Interface Class That Will Work With Any Application

13 posts / 0 new
Last post
Anonymous

I was hammering Brandon on issues with his sample code, so he asked me to post what I had .. which meant i had to document it.

This is different from the other samples, in that it only handles the retrieval and caching of thumbnails. It is up to the calling application to decide what to do if an image is not available and to produce the html code, but that is the way it should be.

btw, that page shows the actual code from my php utilities, that is in production use. An example of an application that I am using the thumbnails in:

http://www.koaladir.com/demo/phpld.php

Update (03/04/2016): This post is very old, but the PHP5 class written by Entrepan can be downloaded here. However, the PHP Sample Code provided in our Documentation Area is much newer and likely more updated.

puravida's picture
puravida
Jedi Warrior
Offline
Joined: 09/01/2007
Visit puravida's Website

Very cool, koaladir. Thank you.

Also, your alpha app really looks good. Great way to see what you're working with!

The only correction I have is that you can also use "xlg" to get the largest default size at 320x240.

Great work on the class, by the way.

Ciao,

Brandon

Anonymous

Ahh, xlg, i like! Using thumbnails for visual confirmations just got a whole lot nicer..

puravida's picture
puravida
Jedi Warrior
Offline
Joined: 09/01/2007
Visit puravida's Website

Hey Koaladir,

I just remembered to mention that you named your pages and link on your site "Share The Web" instead of "Shrink The Web"...

If you name them correctly, you might get more organic traffic from people searching for that type of query. We get a good bit of traffic monthly from people searching for "STW" or "ShrinkTheWeb" + (some code reference)

Just a thought...

Cheers,

Brandon

Anonymous

Thanks, I just updated the page titles, I can't tell you how many times i have typed that other url in by mistake, slow learner Smile

Anonymous

Hello,

This script looks like it does exactly what I need. I just don't understand how to call it.

Does the source call the class? I've been staring at the code and can't figure out how the source and the class interact, let alone how to call them to produce a cached thumbnail.

Any help would be very appreciated.

Thanks

Tim

puravida's picture
puravida
Jedi Warrior
Offline
Joined: 09/01/2007
Visit puravida's Website
sitereview wrote:
Please understand I am not the type of person to just post on forums without first trying every avenue I see. Posting on a forum is truly the last resort.

No problem... I'm not trying to be difficult but just want to be sure.

Just to clarify some basics:

1. you will need to have a source file (something like the 'sample source' provided at the entrepan site)

2. you will need to include the 'AppSTW Class' file contents inside the source file OR you can save it onto your server and "include" it into the source file

After that point, it may not be so obvious on usage, so you basically need to know that once the AppSTW Class is available (however you chose to do it --i.e. #2 above), you can then use one of the following:

showImage("Direct Call Example", AppSTW::queryRemoteThumbnail($url, $args, true));
showImage("Cached Call Example", AppSTW::getThumbnail($url, $args));
showImage("Large Scaled Image", AppSTW::getLargeThumbnail($url, true, true));
showImage("Small Scaled Image", AppSTW::getSmallThumbnail($url, true, true));
showImage("Scaled Image", AppSTW::getScaledThumbnail($url, 640, 480));

Those will display the sample images as defined in the "showImage" function block. If you want more granular control for each call, you would need to call the queryRemoteThumbnail($url, $args, true) function directly and make the result equal some argument. That way, you can manipulate the output as needed. I would be more specific on that, but I haven't really delved into entrepan's code enough to do so.

Hopefully that helps?

Best regards,

Brandon

Anonymous

Hello,

Thank-you very much for helping me. It's so good to finally see some awesome looking thumbnails!

I have a quick question regarding:
$name = md5($url.serialize($args)).".jpg";
I'm just wondering why and whether we have to encrypt the filename to an MD5 hash?

Is this for security?

Thank-you very much again for your help.

Tim

puravida's picture
puravida
Jedi Warrior
Offline
Joined: 09/01/2007
Visit puravida's Website
sitereview wrote:
I'm just wondering why and whether we have to encrypt the filename to an MD5 hash?

Is this for security?

You are quite welcome for the help.

And, yes, it is as you guessed, for security. Using MD5 hash for filenames will keep people from "leeching" off of your cached thumbnails. It probably wouldn't be a problem to just name them whatever URL you are calling but if you are concerned about "leeching", you can leave it as-is.

Cheers,

Brandon

Anonymous

Thanks again for your help.Laughing out loud

I have implemented the script to work perfectly in caching a large thumbnail on a single page, however have run into issues when trying to implement it on a page that lists multiple thumbnails.

The page operates on a loop.

However, when I insert

<?php
$values = get_post_custom_values("TDOMF Form #3 Custom Field #4");
$url = $values[0];
function showImage($label, $src)
{
  if ($src) {
        // The extra ? is so our servers bypass varnish, a reverse proxy
        echo "<img src=$src?>";
    } else
        echo 'Arg... Wheres the image?'; // use some default image
}
showImage("Small Scaled Image", AppSTW::getSmallThumbnail($url, true, true));
?>

anywhere inside the loop, the whole thing dies after just a single execution.

So I end up with 1/10th of the page loaded (the page should load 10 thumbs) but not much else.

I am using Wordpress so I am not sure if you are familiar with their looping system.

I tried moving the variables, taking out the if and else statements, including it else where, but it still crashes after a single execution. I have also searched for information on wordpress's end, but perhaps this is a more general php thing?

Thanks for any insight or advice you can provide. Laughing out loud

rupom (not verified)

Hi Jedi,
I'm facing an issue with thumbnailing. API requests from my domain always getting responses like "fix_and_retry, Lock to account: domain or IP not listed none", etc. But a direct link to your domain (on browser) generates a good XML response. I've tried by your recommended API as well.

For example:

http://images.shrinktheweb.com/xino.php?stwu=MY_UID&stwaccesskeyid=MY_ACCESS_KEY&testcase=1&stwurl=www.wordpress.com

This gives me good XML response when I put on browser, but doesn't work when I try from my domain. I use file() or file_get_contents() PHP functions.

Can you please help me in this regard?

Thanks in advance!

--
Rupom

ShrinkTheWeb® (About STW) is another innovation by Neosys Consulting
Contact Us | PagePix Benefits | Learn More | STW Forums | Our Partners | Privacy Policy | Terms of Use

Announcing Javvy, the best crypto exchange and wallet solution (coming soon!)

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