How to make sketches with php

I am just wondering how I can create thumbnails of images stored in hdd and use them in html page, also I need thumbnails to be able to enlarge (to their original size) if I click on preferably inside a div tag on the same page, I would appreciate it if someone could put me in the right direction

thank

+2


source to share


8 answers


You will need the GD extension. The following code will create a thumbnail file in a subdirectory ~tmb

for JPEG, PNG, and GIF files:

$invalid = true;
if ($file != '.' and $file != '..') {
    if (filetype($path_abs.$file) == "file") {
        $ext = strtolower(substr($file,strrpos($file,'.')+1));
        if ($ext == 'jpg' || $ext == 'jpeg') {
            $origimg = @imagecreatefromjpeg($path_abs.$file);
        } elseif ($ext == 'png') {
            $origimg = @imagecreatefrompng($path_abs.$file);
        } elseif ($ext == 'gif') {
            $origimg = @imagecreatefromgif($path_abs.$file);
        }
        if ($origimg !== false) {
            $nheight = 0;
            $nwidth = 0;
            $use_orig = false;
            if ($width<=160 and $height<160) {
                $nwidth = $width;
                $nheight = $height;
                $use_orig = true;
                $invalid = false;
            } else {
                if ($width>$height and $width>0) {
                    $nheight = intval((160 / $width) * $height);
                    $nwidth = 160;
                } elseif ($height>0) {
                    $nwidth = intval((160 / $height) * $width);
                    $nheight = 160;
                } else {
                    $image = false;
                }
                if ($nheight > 0 and $nwidth > 0) {
                    $newimg = imagecreatetruecolor($nwidth, $nheight);
                    $bgc = imagecolorallocate ($newimg, 238, 238, 238);
                    imagefilledrectangle ($newimg, 0, 0, $nwidth, $nheight, $bgc);
                    if (@imagecopyresampled($newimg, $origimg, 0, 0, 0, 0, $nwidth, $nheight, $width, $height)) {
                        $image = imagejpeg($newimg, $path_abs.'~tmb/'.$file);
                        $invalid = false;
                    } elseif (@imagecopyresized($newimg, $origimg, 0, 0, 0, 0, $nwidth, $nheight, $width, $height)) {
                        $image = imagejpeg($newimg, $path_abs.'~tmb/'.$file);
                        $invalid = false;
                    }
                }
            }
        }
    }
}
if (!$invalid) {
    if ($use_orig) {
        echo '<img src="'.$file.'" alt="" />';
    } else {
        echo '<img src="~tmb/'.$file.'" alt="" />';
    }
} else {
    echo '<p>Error for file '.$file.'</p>';
}

      



In the above code, it resizes to 160x160 even though the aspect ratio is maintained.

+5


source


The gd library allows you to manipulate images. You will find an article for sketching here .



If you want to allow users to view the thumbnail and original size, the best way is to keep two versions. And to display one or the other.

+3


source


its so easy if you have questions by mail to karthid@in.com

$ffmpeg = "ffmpeg Installed path"

$flvfile = "source video file with root path"

$png_path " "Destination video file with root path and file type"

exec("$ffmpeg -y -i $flvfile -vframes 1 -ss 00:01:60 -an -vcodec png -f rawvideo -s 110x90 $png_path");

      

all the best....

+1


source


You can use the GD library in PHP to upload and resize images to generate thumbnails

http://us.php.net/manual/en/image.examples.php

0


source


Find the PECL Imagick extension. It is usually installed with standard package managers.

http://se2.php.net/Imagick

You can dynamically create thumbnails and serve them with .php files (slow) or create a copy of the thumbnail that you keep on the server (prefer)

0


source


the best way I've found is using the phpThumb class ( http://phpthumb.sourceforge.net/ ).

It has everything you need and more, including caching, filters, watermarks, and other cool stuff. Just check out the demo page.

0


source


maxImageUpload is useful for creating thumbnails, regular image with original image.

You can use jQuery to enlarge the thumbnail image.

0


source


In my experience GD is not very memory efficient for large images, so I highly recommend that you use Imagick. I wrote a code snippet to generate thumbnails with php using Imagick library. You can change it to save the image instead of echoing using http://php.net/manual/en/imagick.writeimage.php

0


source







All Articles