开发者

dynamic thumbnail with php

I want to dynamically generate thumbnails, and I found from one of posts here a recommendation that uses SimpleImage class, it is usage like this:

header('Content-Type: image/jpeg');
include('SimpleImage.php');
$image = new SimpleImage();
$image->load('picture.jpg');
$image->resizeToWidth(150);
$image->output();

and the output method is as following:

function output($image_type=IMAGETYPE开发者_如何学Python_JPEG) {

    if( $image_type == IMAGETYPE_JPEG ) {
       imagejpeg($this->image);

    } elseif( $image_type == IMAGETYPE_GIF ) {
       imagegif($this->image);

    } elseif( $image_type == IMAGETYPE_PNG ) {
       imagepng($this->image);

    }
}

this works fine with outputing images, because I received something like binary code on client side. but what I want is a thumbnail slider, so I need all image to be in a <ul></ul>, I tried this using ajax:

updated

function thumb($files){
    echo '<ul>';
    foreach($files as $file){
        $thumb = new Thumbnail();
        $thumb->load($file->getFilePath());
        $thumb->resizeToWidth(80);
        echo '<li>'.$thumb->output().'</li>';
    };
    echo '</ul>';
}

but this does not seem to work. how can I get output something like this so I can do a slider gallery.

<ul>
  <li><img src="path here"></li>
  <li><img src="path here"></li>
</ul>


You're confusing two things: html layout of images and the scaling of images. You need to keep your scaling code - which is perfectly fine - in a separate php file, say, scale.php - like this:

<?php
    header('Content-Type: image/jpeg');
    include('SimpleImage.php');
    $image = new SimpleImage();
    $image->load($_GET['image']);
    $image->resizeToWidth(150);
    $image->output();
?>

And in your main php, you'll have a code like this:

<?php
    echo '<ul>';
    foreach($files as $file){
        echo '<li><img src="scale.php?image=' . $file . '"/></li>';
    }
    echo '</ul>';
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜