Heya,
I was working on a program that would convert a colored image into a black and white one. But when I tried to preview or save the picture, I would get this error.
Warning: imagefilter() expects parameter 2 to be long, string given in C:\xampp\htdocs\Chapter 7\modifyimage.php on line 28
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\Chapter 7\modifyimage.php:28) in C:\xampp\htdocs\Chapter 7\modifyimage.php on line 32
ÿØÿà�JFIF������ÿþ�>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality ÿÛ�C� $.' ",#(7),01444'9=82<.342ÿÛ�C 2!!22222222222222222222222222222222222222222222222222ÿÀ�„X"�ÿÄ����������� ÿÄ�µ���}�!1AQa"q2‘¡#B±ÁRÑð$3br‚ %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖרÙÚáâãäåæçèéêñòóôõö÷øùúÿÄ������ .... (and so on)
Here's my coding:
modifyimage.php
<?php
$id = $_POST['id'];
if (isset($_POST['bw'])) {
$bw = $_POST['bw'];
} else {
$bw = '';
}
$action = $_POST['action'];
$getpic = mysql_query("SELECT * FROM images WHERE image_id = '$id'")
or die(mysql_error());
$rows = mysql_fetch_array($getpic);
extract($rows);
$image_filename = "images/" . $image_id . ".jpg";
list($width, $height, $type, $attr) = getimagesize($image_filename);
$image = imagecreatefromjpeg("$image_filename");
if ($bw == 'on') {
imagefilter($image, IMG_FILTER_GREYSCALE);
}
if ($action == "preview") {
header("content-type:image/jpeg");
imagejpeg($image);
}
if ($action == "save") {
imagejpeg($image, $image_filename);
$url = "location:showimage.php?id=". $id . "&mode=change";
header($url);
}
?>
showimage.php
<?php
$id = $_REQUEST['id'];
if (isset($_REQUEST['mode'])) {
$mode = $_REQUEST['mode'];
} else {
$mode = '';
}
// get info on the pic we want
$getpic = mysql_query("SELECT * FROM images WHERE image_id = '$id'")
or die(mysql_error());
$rows = mysql_fetch_array($getpic);
extract($rows);
$image_filename = "images/" . $image_id . ".jpg";
list($width, $height, $type, $attr) = getimagesize($image_filename);
?>
<html>
<head>
<title>Here is your pic!</title>
<body>
<h1>So how does it feel to be famous?</h1><br><br>
<?php
if ($mode == 'change') {
echo "<font color=\"CC0000\"><em><strong>Your image has been
modified.</strong></em></font>";
echo "<img scr=\"" . $image_filename . "\" align=\"left\" " .
$attr . ">";
} else {
?>
<p>Here is the pciture you just uploaded to our servers:</p>
<img src="<?php echo $image_filename; ?>" align="left"
<?php echo $attr; ?> >
<strong><?php echo $image_caption; ?></strong><br>
It is <?php echo $width; ?> pixels wide a
nd <?php echo $height; ?> pixels high.<br>
It was uploaded on <?php echo $image_date; ?>
by <?php echo $image_username; ?>.
<?php
}
?>
<hr><em><strong>Modifying Your Image</strong></em></p>
<form action="modifyimage.php" method="post">
<p>
Please choose if you would like to modify your image with any of
the following options. If you would like to preview the image
before saving, you will need to hit your browser's 'back' button
to return to this page. Saving an image with any of the
modifications listed below <em>cannot be undone.</em>
</p>
<input name="id" type="hidden" value="<?php echo $image_id; ?>">
<input name="bw" type="checkbox">black & white<br>
<p align="center">
<input type="submit" name="action" value="preview">
<input type="submit" name="action" value="save">
</p>
</form>
</body>
</html>
Any help would be appreciated. Thanks 🙂