Jump to content

Recommended Posts

I am trying to create thumbnails of images that I upload but I just want a thumbnail of the whole image just smaller resolution. I have the upload script done I just need to know two things:

1. how do I copy images.
2. how do I resize the copied image.

If someone could post up some stuff that would be greatly appreciated.

Thanks,
Jr-
Link to comment
https://forums.phpfreaks.com/topic/35538-php-image-help/
Share on other sites

I don't know if this is what you want, it creates a thumbnail and saves it, just change the 300 at the very bottom to how ever wide you want the image.

[code=php:0]
<?php
function createThumbnail($imageDirectory, $imageName, $thumbDirectory, $thumbWidth, $quality = 100)
{
    # function should be called createJpegThumbnail();
    # $quality = 100 is maximum quality
    # file size will come down for lower quality level
    $srcImg = imagecreatefromjpeg("$imageDirectory/$imageName");
    $thumbHeight = ($origHeight = imagesy($srcImg)) * ($thumbWidth / ($origWidth = imagesx($srcImg)));
    $thumbImg = imagecreatetruecolor($thumbWidth, $thumbHeight);
    imagecopyresampled($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $origWidth, $origHeight);
    imagejpeg($thumbImg, "$thumbDirectory/$imageName", $quality);
    imagedestroy($srcImg);
    imagedestroy($thumbImg);
}

createThumbnail("images/graphics", "$name", "images/graphics/thumbs", 300);
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/35538-php-image-help/#findComment-168241
Share on other sites

hmm... tried using the function you posted Little Guy but get this error. Do you know why?

Warning: imagejpeg(): Unable to open 'image/pic.jpg' for writing in photos.php on line 127

This is what I put in:

$fileDirectory = "image";

createThumbnail($fileDirectory , "pic.jpg", $fileDirectory , 50);
Link to comment
https://forums.phpfreaks.com/topic/35538-php-image-help/#findComment-168310
Share on other sites

Ok, I keep trying this:





<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>


<?


$myImage = "test.jpg";

function createThumbnail($imageDirectory, $imageName, $thumbDirectory, $thumbWidth, $quality = 100)
{
    # function should be called createJpegThumbnail();
    # $quality = 100 is maximum quality
    # file size will come down for lower quality level
    $srcImg = imagecreatefromjpeg("$imageDirectory/$imageName");
    $thumbHeight = ($origHeight = imagesy($srcImg)) * ($thumbWidth / ($origWidth = imagesx($srcImg)));
    $thumbImg = imagecreatetruecolor($thumbWidth, $thumbHeight);
    imagecopyresampled($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $origWidth, $origHeight);
    imagejpeg($thumbImg, "$thumbDirectory/$imageName", $quality);
    imagedestroy($srcImg);
    imagedestroy($thumbImg);
}

createThumbnail("image", $myImage, "image", 50);

?>


</body>
</html>




...and get this error:



Warning: imagejpeg(): Unable to open 'image/test.jpg' for writing in /usr/local/pem/vhosts/116423/webspace/httpdocs/grayfire/photos/uploadTest_2.php on line 25




It should use the image that I have in a directory and output a thumbnail of that image to the browser right?

Thanks,
Jr-
Link to comment
https://forums.phpfreaks.com/topic/35538-php-image-help/#findComment-169501
Share on other sites

yeah that's how it is but I still get that error. Also I was having trouble trying to get the image to save to a file instead of trying to output it to the browser but I couldn't get that to work either. Do I have something wrong with the code that I can't get this to work either of those ways? Thanks again for all of the help.  ;)
Link to comment
https://forums.phpfreaks.com/topic/35538-php-image-help/#findComment-169535
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.