För stor, kan man minska?
Ingen som vet hur man löser problemet då jag inte har möjlighet att få mer memorysize?
När jag försöker ändra storlek på större bilder (runt 1MiB) så brukar min server inte vilja:
kod:
--------------------------------------------------------------------------------
Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 4096 bytes) ...
--------------------------------------------------------------------------------
Det där gällde funktionen imagecreatefromjpeg() när jag stoppade in en fil på 1,2MiB.
Den storleken är ju inte för mycket (allowed memory size = 8MiB).
Vad skapar imagecreatefromjpg() som blir så stort?
Finns det något bra sätt att hantera stora bilder?
problemet uppstår ju när man kör imagecreatefromjpg()
Skulle det vara möjligt att innan denna förminska kvaliten (storleken på bilden) så att man sen kan köra vidare.
Jag försöker få ordning på et script från hotscript.
function.php
<?
/*
* This script is copyright PHPGarage.com (On Line Construction Inc.). It may be used,
* changed, and distributed freely as long as this message and/or some type of recognition
* is given to PHPGarage.com or On Line Construction Inc.
*
* [url]http://www.phpgarage.com[/url]
* [url]http://www.onlineconstructioninc.com[/url]
*
*/
function ResizeImage($im,$maxwidth,$maxheight,$name){
$width = imagesx($im);
$height = imagesy($im);
if(($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight)){
if($maxwidth && $width > $maxwidth){
$widthratio = $maxwidth/$width;
$RESIZEWIDTH=true;
}
if($maxheight && $height > $maxheight){
$heightratio = $maxheight/$height;
$RESIZEHEIGHT=true;
}
if($RESIZEWIDTH && $RESIZEHEIGHT){
if($widthratio < $heightratio){
$ratio = $widthratio;
}else{
$ratio = $heightratio;
}
}elseif($RESIZEWIDTH){
$ratio = $widthratio;
}elseif($RESIZEHEIGHT){
$ratio = $heightratio;
}
$newwidth = $width * $ratio;
$newheight = $height * $ratio;
if(function_exists("imagecopyresampled")){
$newim = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}else{
$newim = imagecreate($newwidth, $newheight);
imagecopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}
ImageJpeg ($newim,$name . ".jpg");
ImageDestroy ($newim);
}else{
ImageJpeg ($im,$name . ".jpg");
}
}
?>
och filen shrinkimage.php
<?
/*
* This script is copyright PHPGarage.com (On Line Construction Inc.). It may be used,
* changed, and distributed freely as long as this message and/or some type of recognition
* is given to PHPGarage.com or On Line Construction Inc.
*
* [url]http://www.phpgarage.com[/url]
* [url]http://www.onlineconstructioninc.com[/url]
*
*/
// Filename to store image as (no extention)
$FILENAME="image_name";
// Width to reszie image to (in pixels)
$RESIZEWIDTH=400;
// Width to reszie image to (in pixels)
$RESIZEHEIGHT=400;
// DO NOT EDIT BELOW HERE -----------------------------------------
include("function.php");
if($_FILES['image']['size']){
if($_FILES['image']['type'] == "image/pjpeg" || $_FILES['image']['type'] == "image/jpeg"){
$im = imagecreatefromjpeg($_FILES['image']['tmp_name']);
}elseif($_FILES['image']['type'] == "image/x-png" || $_FILES['image']['type'] == "image/png"){
$im = imagecreatefrompng($_FILES['image']['tmp_name']);
}elseif($_FILES['image']['type'] == "image/gif"){
$im = imagecreatefromgif($_FILES['image']['tmp_name']);
}
if($im){
if(file_exists("$FILENAME.jpg")){
unlink("$FILENAME.jpg");
}
ResizeImage($im,$RESIZEWIDTH,$RESIZEHEIGHT,$FILENAME);
ImageDestroy ($im);
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body bgcolor="#C2C287" text="#000000" id="all" leftmargin="10" topmargin="10" marginwidth="10" marginheight="10" link="#660000" vlink="#660000" alink="#660000">
<br><br>
<img src="<? echo($FILENAME.".jpg?reload=".rand(0,999999)); ?>"><br><br>
<form enctype="multipart/form-data" method="post">
<b>Resize Image</b><br>
<input type="file" name="image" size="50"><br><br>
<input type="submit" value="Upload Photo">
</form>
</body>
</html>
Hoppas på svar