Jump to content

Recommended Posts

Hello,

 

I have this script running:

<?php
//include("include/session.php");
?>
<!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=utf-8" />
<title>Add an Image to Gallery</title>
<link href="../../include/stylee.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrap">
<div id="content">
<form enctype="multipart/form-data" action="<? $_SERVER['PHP_SELF'] ?>" method="post">
<fieldset title="Add Images and Descriptions">
<legend>Add Images and Descriptions</legend>
  <p>
    Choose a file to upload: <br />
    <input name="image" type="file" />
    </p>
<p>Give the Image a Short Description<br />
<input name="ushortdesc" type="text" size="60" maxlength="75" />
</p>
  <p>Give the Image a Long Description<br />
    <textarea name="ulongdesc" cols="60" rows="10"></textarea>
  </p>
  <p>Where does the Image Link to?<br />
  <input name="uimglink" type="text" value="http://www.yoursite.com/yourstore/or..." size="60" />
</p>
  <p>
    <input type="submit" name="upload" value="Upload" />  
</p>
</fieldset>
</form>
</div>
<div id="report">
<?php
//function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth )
//{
//  // open the directory
//  $dir = opendir( $pathToImages );
//
//  // loop through it, looking for any/all JPG files:
//  while (false !== ($fname = readdir( $dir ))) {
//    // parse path for the extension
//    $info = pathinfo($pathToImages . $fname);
//    // continue only if this is a JPEG image
//    if ( strtolower($info['extension']) == 'jpg' )
//    {
//      echo "Creating thumbnail for {$fname} <br />";
//
//      // load image and get image size
//      $img = imagecreatefromjpeg( "{$pathToImages}{$fname}" );
//      $width = imagesx( $img );
//      $height = imagesy( $img );
//
//      // calculate thumbnail size
//      $new_width = $thumbWidth;
//      $new_height = floor( $height * ( $thumbWidth / $width ) );
//
//      // create a new temporary image
//      $tmp_img = imagecreatetruecolor( $new_width, $new_height );
//
//      // copy and resize old image into new image - for gd-1 version
//	//imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
//	//randys alteration for gd-2 version
//	imagecopyresampled( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
//
//      // save thumbnail into a file
//      imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" );
//    }
//  }
//  // close the directory
//  closedir( $dir );
//}
//	// call createThumb function and pass to it as parameters the path
//// to the directory that contains images, the path to the directory
//// in which thumbnails will be placed and the thumbnail's width.
//// We are assuming that the path will be a relative path working
//// both in the filesystem, and through the web for links
//createThumbs("images/","images/thumbs/",100);
//echo "<h2>All Done!</h2>";

if(isset($_POST['upload']))
{
$size = 50; // the thumbnail height

$filedir = 'images/'; // the directory for the original image
$thumbdir = 'thumbs/'; // the directory for the thumbnail image
$prefix = 'thumb_'; // the prefix to be added to the original name

$maxfile = '2100000';
$mode = '0666';

$userfile_name = $_FILES['image']['name'];
$userfile_tmp = $_FILES['image']['tmp_name'];
$userfile_size = $_FILES['image']['size'];
$userfile_type = $_FILES['image']['type'];

if (isset($_FILES['image']['name'])) 
{
	$uimg = $filedir.$userfile_name;
	$uimg_thumb = $thumbdir.$prefix.$userfile_name;
	move_uploaded_file($userfile_tmp, $uimg);
	chmod ($uimg, octdec($mode));

	$sizes = getimagesize($uimg);
	$aspect_ratio = $sizes[0]/$sizes[0]; 

	if ($sizes[0] <= $size)
	{
		$new_width = $sizes[0];
		$new_height = $sizes[0];
	}else{
		$new_height = $size;
		$new_width = abs($new_height/$aspect_ratio);
	}

	$destimg=ImageCreateTrueColor($new_width,$new_height)
		or die('Problem In Creating image');
	$srcimg=ImageCreateFromJPEG($uimg)
		or die('Problem In opening Source Image');
	if(function_exists('imagecopyresampled'))
	{
		imagecopyresampled($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg))
		or die('Problem In resizing');
	}else{
		Imagecopyresized($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg))
		or die('Problem In resizing');
	}
	ImageJPEG($destimg,$uimg_thumb,90)
		or die('Problem In saving');
	imagedestroy($destimg);
}

echo '
<a href="'.$uimg.'">
	<img src="'.$uimg_thumb.'" width="'.$new_width.'" heigt="'.$new_height.'">
</a>';
}
?>
</div>
</body>
</html>

 

Works great, except when I upload a 400kb or larger file... Is there some kind of limit to the ability of the GD library?

 

Anyone have a work around?

 

Thanks!

Thanks for the reply.

 

I increased the memory. However, I find that images that are 3000px X 3000px don't work with that either. I noticed 2000px X 200px 6mb files will work... weird.

 

Is there anything other than the php.ini memory doing this?

 

Thanks!

  • 3 years later...

I have noticed that I can upload and use imagecopyresampled for images i varios sizes (px) as well as sizes (kb).

 

As soon as the size (px) goes above some kind of limit the script dosen't work.

 

I kan use an image of 3499x3499 px in 4500kb but not an image of 3500x3500 px in 586kb, this dosn't make sens to me!

 

Any one how can tell about this problem? How to calculate the maximum pixels!?

 

thks

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.