Jump to content

[SOLVED] IMAGE RESIZING HELP! - noob-


SilentQ-noob-

Recommended Posts

Hi,

 

I want to make a piece of code where I have a form with the fields width and height. The forced dimensions of the image are W: 120 and H: 90. I want to make two boxes with the names width and height, and when somebody enters nwe numbers into the fields and clicks resize, the image resizes accordingly.

 

I've got the HTML form:

 

<img id="pic" src="images/click.jpg" width="120" height="90">

<br/>

<form action="form.php" method="post">

<caption>Enter new numbers to resize the image</caption><br/>

Width: <input name ="width" type="text" value="120">

<br/>

Height: <input name ="height" type="text" value="90">

<br />

<input type="submit" value="RESIZE">

 

</form>

 

I think what I have to do is create variables $height and $width, and then update them with values from $_POST['height'] and $_POST['width']

 

- I just dont know how to make a function that sets the new height and width values to that of what the user has put in

 

ANY help would be GREATLY appreciated!!! thanks

-AMMAR

Link to comment
https://forums.phpfreaks.com/topic/59546-solved-image-resizing-help-noob/
Share on other sites

fromt he example on php.com

 

put this code in image.php

<?php
// File and new size
$filename = 'images/click.jpg';
//$percent = 0.5;

// Content type
header('Content-type: image/jpeg');

// Get new sizes
//list($width, $height) = getimagesize($filename);
//$newwidth = $width * $percent;
//$newheight = $height * $percent;

// Load
$thumb = imagecreatetruecolor($_GET['width'], $_GET['height']);
$source = imagecreatefromjpeg($filename);

// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Output
imagejpeg($thumb);
?>

 

and this code in form.php

<b>Resized image</b>
<?
echo "<img src='image.php?width=".$_POST['width']."&height=".$_POST['height']."'>";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.