|
#1
|
|||
|
|||
|
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? |
|
#2
|
||||
|
||||
|
How do you know the problem is hitting memory_limit and not another issue?
__________________
Follow me on Twitter! http://twitter.com/mrw |
|
#3
|
|||
|
|||
|
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'); ?> |
|
#4
|
|||
|
|||
|
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'); ?> |
|
#5
|
|||
|
|||
|
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?
|
|
#6
|
|||
|
|||
|
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 |
|
#7
|
||||
|
||||
|
Sergey,
It worked fine for me. Are you sure your image path is correct? -Matt
__________________
Follow me on Twitter! http://twitter.com/mrw |
|
#8
|
|||
|
|||
|
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! |
|
#9
|
||||
|
||||
|
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 |
|
#10
|
|||
|
|||
|
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
|
|
#11
|
||||
|
||||
|
No problem, and glad I could help!
__________________
Follow me on Twitter! http://twitter.com/mrw |
![]() |
| Bookmarks |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
|
|
All times are GMT -5. The time now is 07:44 AM.








