Don't use RENDER_NOW. It's the complete opposite of what he's asking for. In fact NEVER use RENDER_NOW unless you are absolutely sure that you absolutely need it. The only valid use case for RENDER_NOW I can think of is if you intend to open the file yourself and do extra image processing on it. If you want to give a user a URL then you NEVER need it.

My input on this subject:
- If your thumbnail size is larger than the image's size then the original image's url will be returned because it's already big enough (this IS what you want) - If you have setup a 404 handler files will only be generated when they are requested by the user. This IS what you want.

We support generating thumbnails when a file is not found. If a path looks like a thumbnail it gets sent to thumb.php where it's then rendered, sent to the user, and saved to the filesystem for future requests.
This has a number of advantages:
- You can delete all your thumbnails if you think you have piles ones not being used anymore. Since they will all safely be regenerated when used. - You can use thumbnails inside of css since you know the thumb will always be usable. - It speeds up your wiki. Rendering thumbnails takes time. And during the time that thumbnails are being generated php is frozen. That means that thumbnail render time adds to your wiki's page load time on upload, save, previews, view, etc... By using a 404 handler the wiki is capable of skipping the rendering serving a url and deferring that load time to a process dedicated to rendering the thumbnail. - It also lets you dedicate machines to image thumbnailing and allow your webservers to focus on serving webpages instead of spending cpu time on image processing.

One of these days I'd like to see if I could write a fuse filesystem that exposes a cache as a filesystem. ;) then you can mount that as your filesystem for thumbs/ and have all old thumbnails purged automatically. (We don't have the capability to delete thumbnails that are no longer used)


On Tue, 27 Mar 2012 22:13:23 -0700, Hunter Fernandes <h.g.f...@gmail.com> wrote:

Since no one has replied at this time, I thought I'd give a crack at an
answer (I really don't know if this will work).

Some goodies from a quick scan of thumb.php:

$img = wfLocalFile( $fileName );
$params = array(
'width' => 100,
'height' => 100,
);
$img->transform( $params, File::RENDER_NOW );
$localpath = $thumb->getPath();
$thumbPath = $img->getThumbPath( $thumbName );

That's my guess. I havn't tested it or anything.
- Hunter F.


On Tue, Mar 27, 2012 at 7:03 PM, Daniel Renfro <dren...@vistaprint.com>wrote:

MW gurus,

I am working on an API module to an extension and would like to create
thumbnails programmatically for some images (if they don't already have
them.)

The includes/filerepo/File.php file contains a createThumb() method, which
looks like it's what I want. From the comment block directly above the
aforementioned method:
   /**
    * Create a thumbnail of the image having the specified width/height.
    * The thumbnail will not be created if the width is larger than the
    * image's width. Let the browser do the scaling in this case.
* The thumbnail is stored on disk and is only computed if the thumbnail
    * file does not exist OR if it is older than the image.
    * Returns the URL.
    *
    * ....
    */

However, this method always returns the url of the file itself and not the thumb. From what I can tell it never generates the thumbnail (it's not in
the filesystem repo in any directory.) My code is:

<?php

# ...query to get a list of recently uploaded images (quite simple) ....
$result =  $dbr->select();

# loop through them and get a thumbnail & url
foreach ( $result as $row ) {
 $title = Title::newFromText( $row->page_title, NS_FILE );
 $file = wfFindFile( $title );
 if ( !$file ) {
   continue;
 }
 $thumbnail_url = $file->createThumb( 80 ); # width in pixels
 ...add to the API result...
}
...return...

?>

I'm sure that my query return valid page titles/namespaces, and that the
files exist (both in the wiki and in the filesystem.) They are all local,
and some are quite large. I'd hate to have to send the entire image and
make the browser do the scaling, as the thumbnail will get reused and the
resizing is only done once.

Any ideas fellow MW gurus? What am I missing?

-Daniel Renfro

--
~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://daniel.friesen.name]

_______________________________________________
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Reply via email to