Jump to content

Recommended Posts

I concerned about resizing images, currently i resize images by simply stretching them out or making them smaller, but sometimes if i upload a picture that is more horizontal then vertical then the image can become distored or vice versa...is there a way i can upload and resize the image so that the image isn't distorted?

Link to comment
https://forums.phpfreaks.com/topic/150192-resizing-image-to-proper-resolution/
Share on other sites

how should i put it in this code...this is to reze for larger image

 

<?php
// Create MySQL login values and 
// set them to your login information.
$username = "root";
$password = "";
$host = "localhost";
$database = "userimages";

// Make the connect to MySQL or die
// and display an error.
$link = mysql_connect($host, $username, $password);
if (!$link) {
    die('Could not connect: ' . mysql_error());
}

$connect = mysql_select_db($database) or die("Can not select the database: ".mysql_error());


$id = $_GET['id'];

if(!isset($id) || empty($id)){
die("Please select your image!");
}else{

$query = mysql_query('SELECT `image` FROM `tbl_images` WHERE `userid`= "'.$id.'"');
$row = mysql_fetch_assoc($query);
$content = $row['image'];



$desired_width = 300; 
$desired_height = 225; 

$im = imagecreatefromstring($content)or die("Can not select the database: ".mysql_error());; 
$new = imagecreatetruecolor($desired_width, $desired_height)or die("Can not select the database: ".mysql_error());; 

$x = imagesx($im); 
$y = imagesy($im); 

imagecopyresampled($new, $im, 0, 0, 0, 0, $desired_width, $desired_height, $x, $y)or die("Can not select the database: ".mysql_error());; 

imagedestroy($im); 

header('Content-type: ' . $row['type'] .'');
imagejpeg($new, null, 85);
}
?>

still experiencing trouble. im trying to get it from the url. is there another way

 

when doing that i get this error

 

Fatal error: Call to undefined function resamplimgimagecopyresampled() in /home/username/public_html/profile/index.php on line 79

 

my image url is created from the code above

 

and i use this in profile image display

 

$large_image = imagecreatefromjpeg( "http://www.domain.com/image/viewlarge.php?id=$id" );
## provided the dimension of the new smaller image
$x = 180;$y = 180;
## create a black blank image with provided dimension
$small_image = imagecreatetruecolor($x,$y);
## Just copy the larger image into the smaller image using 
resamplimgimagecopyresampled($small_image,$large_image,0,0,0,0,$x,$y,imagesx($large_image),imagesy($large_image));
## Its always better to free the memory if you don't need 
thisimagedestroy($large_image);
## Just ignore the file name.# 
imagejpeg($small_image);
## Once again, free the 
memeoryimagedestroy($small_image);

 

line 79 being

 

resamplimgimagecopyresampled($small_image,$large_image,0,0,0,0,$x,$y,imagesx($large_image),imagesy($large_image));

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.