Imagecopyresampled() ?

Started on the old forum in November 2008 · view the original in the archive · old links redirect here

4 replies · 403 views · started 18 years ago · 1 min read

2 participants
something else Fellow · 2,296 posts #1

Iv been creating some thumbnail pictures using imagecopyresampled() it works fine on most pics untill it gets to large size pictures (width/height) and then it stops working 🙁 i know that the the pic size isnt to much as its about 250kb and iv been resizing some well over that. as the soloution then would be to set memory up higher in php.ini ini_set('memory_limit', '30M'); so im guessing it has something to do with the width of the picture which is 2039 x 1631 pixels im trying to resize to 100 x 100 pixels both input and output of the pic is in jpg Does anyone know if there is a height/width pixel limit? if so what is it? 🙂

something else Fellow · 2,296 posts #2

iv set limit at 1000 pixels squared but if anyone knows any differnt would be much apprecaited

rukiya Lead · 569 posts #3

QUOTE

so im guessing it has something to do with the width of the picture which is 2039 x 1631 pixels im trying to resize to 100 x 100 pixels

100x100 resized image from 2039x1631 image wont produce an actual resized image. You should resize it uniformly like 203.9x163.1 .

So try to think simply like this

<?php 
$c = "10"; //// changable
$image = "test.jpg"; /// gif/png
$rukiya = getimagesize($image); 
$a = $rukiya[0]/$c;
$b = $rukiya[1]/$c;
echo "<img src=\"$image\" height=\"$a\" weight=\"$b\"/>";
?>
something else Fellow · 2,296 posts #4

yeah unfortunately load time doing it that way is to long 🙁

would running from 2039x1631 to 1000 x 1000 pixels work? and then running a second time to 100 x 100 ? 🙂

guess there is only 1 way to find out........ lol

Guest #5
<?php
/* How to use? 
Simple, image.php?file=imageurl
or image.php?file=http://file.com/images/image.jpg
*/

//adjust size
$height= 100;
$width= 100;

$filename= $_GET["file"];
// Content type
header('Content-type: image/jpeg');
if(!$filename)
$filename="./images/nopic.jpg";
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);

if ($width && ($width_orig < $height_orig)) {
   $width = ($height / $height_orig) * $width_orig;
} else {
   $height = ($width / $width_orig) * $height_orig;
}

// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

// Output
imagejpeg($image_p, null, 100);
ImageDestroy ($image_p);
?>

Try this script, make it something like image.php or something. This should work!

Sign in to reply.

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close