Go Back   HostGator Peer Support Forums > Public Forums > Suggestions

Notices

Reply
 
Thread Tools
  #1  
Old 03-26-2008, 06:18 PM
Sergey Sergey is offline
Hatchling Croc
 
Join Date: Mar 2008
Posts: 31
Default imagecreatefromjpeg and memory limit problem

I want is to do photo thumbs using php.
I have problems with test php script on dedicated accounts:

<?php
$im = imagecreatefromjpeg('test2M.jpg');
?>

Shared and reseller has memory limit.
On dedicated I set memory limit to 100M, but it's still not enough for 2M file.

Even 30M is enogh on local php 5.

Is any ideas how much I have to set on dedicated? And is it safe?
Maybe you know another solution to convert images using php?
Reply With Quote
  #2  
Old 03-26-2008, 06:59 PM
slapshotw's Avatar
slapshotw slapshotw is offline
Veteran Croc
 
Join Date: Jun 2006
Posts: 5,164
Default Re: imagecreatefromjpeg and memory limit problem

How do you know the problem is hitting memory_limit and not another issue?
__________________
Follow me on Twitter! http://twitter.com/mrw
Reply With Quote
  #3  
Old 03-27-2008, 06:53 AM
Sergey Sergey is offline
Hatchling Croc
 
Join Date: Mar 2008
Posts: 31
Default Re: imagecreatefromjpeg and memory limit problem

I do not know.

Please could you run this simple script and tell why it's not working?
(Use can use any 2M jpg photo from your camera)

<?php
$im = imagecreatefromjpeg('test2M.jpg');
?>
Reply With Quote
  #4  
Old 04-03-2008, 03:38 PM
Sergey Sergey is offline
Hatchling Croc
 
Join Date: Mar 2008
Posts: 31
Default Re: imagecreatefromjpeg and memory limit problem

slapshotw, Please could you run this simple script and tell why it's not working?
(Use can use any 2M jpg photo from your camera)

<?php
$im = imagecreatefromjpeg('test2M.jpg');
?>
Reply With Quote
  #5  
Old 04-04-2008, 05:21 PM
bcmiller bcmiller is offline
Hatchling Croc
 
Join Date: Jun 2006
Location: Melbourne, Australia
Posts: 23
Default Re: imagecreatefromjpeg and memory limit problem

I'm no expert on image creation (I'm more like a n00b), but don't you have to set thumbnail image sizes before executing that line?
Reply With Quote
  #6  
Old 04-04-2008, 05:30 PM
bcmiller bcmiller is offline
Hatchling Croc
 
Join Date: Jun 2006
Location: Melbourne, Australia
Posts: 23
Default Re: imagecreatefromjpeg and memory limit problem

This is a file I have used for a 'once' off batch of thumbnails.
Stick this file in the directory with the images, them access the file in your browser. It will create thumbnails for every image in the directory in another directory called 'thumbs'.
It easily handles 2mb files on a shared server. Perhaps you could modify it to suit?

I would love to credit the original author, but I don't know who it was. Sorry.
Code:
<?php 
$imagefolder='.';
$thumbsfolder='thumbs/';
$pics=directory($imagefolder,"jpg,JPG,JPEG,jpeg,png,PNG");
$pics=ditchtn($pics,"th_");
if ($pics[0]!="")
{
	foreach ($pics as $p)
	{
		createthumb($p,"thumbs/th_".$p,100,100);
	}
}

/*
	Function ditchtn($arr,$thumbname)
	filters out thumbnails
*/
function ditchtn($arr,$thumbname)
{
	foreach ($arr as $item)
	{
		if (!preg_match("/^".$thumbname."/",$item)){$tmparr[]=$item;}
	}
	return $tmparr;
}

/*
	Function createthumb($name,$filename,$new_w,$new_h)
	creates a resized image
	variables:
	$name		Original filename
	$filename	Filename of the resized image
	$new_w		width of resized image
	$new_h		height of resized image
*/	
function createthumb($name,$filename,$new_w,$new_h)
{
	$system=explode(".",$name);
	if (preg_match("/jpg|jpeg|JPG/",$system[1])){$src_img=imagecreatefromjpeg($name);}
	if (preg_match("/png/",$system[1])){$src_img=imagecreatefrompng($name);}
	$old_x=imageSX($src_img);
	$old_y=imageSY($src_img);
	if ($old_x > $old_y) 
	{
		$thumb_w=$new_w;
		$thumb_h=$old_y*($new_h/$old_x);
	}
	if ($old_x < $old_y) 
	{
		$thumb_w=$old_x*($new_w/$old_y);
		$thumb_h=$new_h;
	}
	if ($old_x == $old_y) 
	{
		$thumb_w=$new_w;
		$thumb_h=$new_h;
	}
	$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
	imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); 
	if (preg_match("/png/",$system[1]))
	{
		imagepng($dst_img,$filename); 
	} else {
		imagejpeg($dst_img,$filename); 
	}
	imagedestroy($dst_img); 
	imagedestroy($src_img); 
}

/*
        Function directory($directory,$filters)
        reads the content of $directory, takes the files that apply to $filter 
		and returns an array of the filenames.
        You can specify which files to read, for example
        $files = directory(".","jpg,gif");
                gets all jpg and gif files in this directory.
        $files = directory(".","all");
                gets all files.
*/
function directory($dir,$filters)
{
	$handle=opendir($dir);
	$files=array();
	if ($filters == "all"){while(($file = readdir($handle))!==false){$files[] = $file;}}
	if ($filters != "all")
	{
		$filters=explode(",",$filters);
		while (($file = readdir($handle))!==false)
		{
			for ($f=0;$f<sizeof($filters);$f++):
				$system=explode(".",$file);
				if ($system[1] == $filters[$f]){$files[] = $file;}
			endfor;
		}
	}
	closedir($handle);
	return $files;
}
?>
<a href="/">All done.. Click here to view your work</a>

Last edited by bcmiller; 04-04-2008 at 05:32 PM. Reason: Spelling
Reply With Quote
  #7  
Old 04-05-2008, 12:11 AM
slapshotw's Avatar
slapshotw slapshotw is offline
Veteran Croc
 
Join Date: Jun 2006
Posts: 5,164
Default Re: imagecreatefromjpeg and memory limit problem

Sergey,

It worked fine for me. Are you sure your image path is correct?

-Matt
__________________
Follow me on Twitter! http://twitter.com/mrw
Reply With Quote
  #8  
Old 04-12-2008, 03:19 AM
nulld nulld is offline
Hatchling Croc
 
Join Date: Apr 2008
Posts: 10
Default Re: imagecreatefromjpeg and memory limit problem

i have had a similar issue when creating thumbnails, although the script above worked great for me... although i do have one additional question, is there any way to set the percentage of compression using djpeg, pnmscale, or cjpeg? anyone have a working example? your help is appreciated...

thanks!
Reply With Quote
  #9  
Old 04-12-2008, 03:50 AM
slapshotw's Avatar
slapshotw slapshotw is offline
Veteran Croc
 
Join Date: Jun 2006
Posts: 5,164
Default Re: imagecreatefromjpeg and memory limit problem

You can do it with imagejpeg() in php if you wanted: http://us.php.net/manual/en/function.imagejpeg.php

Does that help?
__________________
Follow me on Twitter! http://twitter.com/mrw
Reply With Quote
  #10  
Old 04-12-2008, 01:02 PM
nulld nulld is offline
Hatchling Croc
 
Join Date: Apr 2008
Posts: 10
Default Re: imagecreatefromjpeg and memory limit problem

wow... i appreciate that post so much!

i swear, the simple things someone can do with their knowledge like that quick post can totally make another persons day. thank you so much
Reply With Quote
  #11  
Old 04-12-2008, 05:26 PM
slapshotw's Avatar
slapshotw slapshotw is offline
Veteran Croc
 
Join Date: Jun 2006
Posts: 5,164
Default Re: imagecreatefromjpeg and memory limit problem

No problem, and glad I could help!
__________________
Follow me on Twitter! http://twitter.com/mrw
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

All times are GMT -5. The time now is 07:44 AM.