Jump to content

Recommended Posts

Hello,

I was wondering if someone would be kind enough to point me in the right direction.

I want to create 2 thumbnails of an uploaded image:

- 1 thumbnail saved in a folder that is 200px Wide x the constrained height.
- 1 thumbnail saved in a folder that is 100px Wide x the constrained height.

I’d also like it to:
- Save the paths of these images in the 2 different folders in a table in a MYSQL database

I know there are loads of scripts out there that are used for thumbnails, but I can’t find one that does this. Could anyone please advise / provide a link to point me in the right direction?

Thanks

Chris
Link to comment
https://forums.phpfreaks.com/topic/12396-thumbnails-script/
Share on other sites

Try this:

[code]
<?php

function makethumb($path,$newwidth,$newpath)
{
    $orgpicture = imagecreatefromjpeg($path);
    $orgwidth = imagesx($orgpicture); //finds the width of original pix
    $orgheight = imagesy($orgpicture); //and height
    $ratio = $orgheight / $orgwidth; //ratio

    $thumbwidth = $newwidth; //set width
    $thumbheight = $thumbwidth * $ratio; //create height

    $thumb = imagecreatetruecolor($thumbwidth, $thumbheight); //create image there the thumb will be located
    imagecopyresampled($thumb, $orgpicture, 0, 0, 0, 0, $thumbwidth, $thumbheight, $orgwidth, $orgheight); //copy the old pix, resize, and drop it in the image we just made

    imagejpeg($thumb, $newpath, 100); //save thumb with max quality (100);
}


makethumb('the/org/path/pix.jpg',100,'the/new/path/pix.jpg');

makethumb('the/org/path/pix.jpg',200,'the/other/new/path/pix.jpg');

?>[/code]

Not testet...

I don't understand the Q about MySQL, but you should be able to figure that out from here, otherwise try again! [img src=\"style_emoticons/[#EMO_DIR#]/wink.gif\" style=\"vertical-align:middle\" emoid=\":wink:\" border=\"0\" alt=\"wink.gif\" /]

-OVA-
Link to comment
https://forums.phpfreaks.com/topic/12396-thumbnails-script/#findComment-47428
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.