Styleminds
asked on
how can i resize image and keep the aspect ratio ?
Hello here is my script used to upload an image so i need to have the size of the image to 150px
note that i am using easyphp that have php 4.0 so i look for a solution that work on it.
PS: please help by adding the resize image to my code structure listed below
note that i am using easyphp that have php 4.0 so i look for a solution that work on it.
PS: please help by adding the resize image to my code structure listed below
function upload($file,$t,$path)
{
$post=$_FILES[$file];
$title=$_POST[$t];
$rand=rand(100,10000);
//upload setting
//$path="../images/products/";
//rename
$remove_these = array(' ','`','"','\'','\\','/');
//Make the filename unique
$type1=explode("/" ,$post['type']);
if ( $post['size'] > 0 ) {
if ( $post['type'] != "image/pjpeg" && $post['type'] != "image/gif" && $post['type'] != "image/bmp" && $post['type'] != "image/jpg" ){
$picture='1';
}
else{
if ( $post['type'] == "image/pjpeg"){ $picture= $title."-".$rand.'.jpg'; }
else{ $picture=$title."-".$rand.".".$type1[1];}
if(move_uploaded_file($post["tmp_name"], $path.$picture ) ) {
chmod($path.$picture, 0777);
$my_new_file = $path.$picture;
} else{ $test=""; }
}
}
else {
$picture='0';
}
return $picture;
}
//here the trick to render the message to the notification div
$print=upload("image","title","../images/sell/products/");
$script='<script type="text/javascript">';
if ( $print == "0" )
{
$script.='parent.document.getElementById("nimage").innerHTML="KINDLY CHOOSE A VALID IMAGE";'. "\n";
$script.='parent.document.getElementById("dimage").style.backgroundColor="#FF4200";'. "\n";
}
if ( $print == "1" )
{
$script.='parent.document.getElementById("nimage").innerHTML="NOT AN IMAGE TYPE! | ONLY JPEG, GIF AND BMP IMAGE ACCEPTED";'. "\n";
$script.='parent.document.getElementById("dimage").style.backgroundColor="#FF4200";'. "\n";
}
else
{
$script.='parent.document.getElementById("nimage").innerHTML="IMAGE SUCCESSFULLY UPLOADED";'. "\n";
$script.='parent.document.getElementById("dimage").style.backgroundColor="#ABCDEC";'. "\n";
$_SESSION['sellimage']=$print;
}
$script.='</script>';
echo $script;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry made a little typo:
if($sourceHeight < $sourceWidth){
$longSide = $sourceWidth;
}
if($sourceHeight < $sourceWidth){
$longSide = $sourceWidth;
}
ASKER
this function return that is undefined !
imagecreatefromjpeg($my_ne w_file);
how can i fix it ?
imagecreatefromjpeg($my_ne
how can i fix it ?
Assuming you're on Windows:
Open a text editor (notepad, etc.).
Open php.ini.
Look for a line like this:
;extension=php_gd.dll
Erase the semicolon (;).
Open a text editor (notepad, etc.).
Open php.ini.
Look for a line like this:
;extension=php_gd.dll
Erase the semicolon (;).
ASKER
there is only
extension=php_gd2.dll
and it didn't have any semocolon!
any idea ! how can i get this function to work ! i just need to remind what i advice above i am using easy php with php4 so i need a solution for this version i don't want to upgrade for the time being.
Thanks.
extension=php_gd2.dll
and it didn't have any semocolon!
any idea ! how can i get this function to work ! i just need to remind what i advice above i am using easy php with php4 so i need a solution for this version i don't want to upgrade for the time being.
Thanks.
can you get the phpinfo. do you see anything like GD in there?
<?php
phpinfo();
?>
ASKER
sorry i get lost ! where i can find this also in php.ini? does this available in php folder as i found another one in the apashe server
please advise.
please advise.
no create a php file and paste the above code in it.
run the file and you'll get all the modules and other information about your current php configuration.
run the file and you'll get all the modules and other information about your current php configuration.
ASKER
if($sourceHeight < $sourceWidth){
$longSide = $oldImage.Width;
}
and the function imagecreatefromjpeg() give this error
Fatal error: Call to undefined function: imagecreatefromjpeg() in i:\easyphp1-8\www\audiomin
so please advice