Hi all,
I am trying to write a script that removes/crops any white space from around an iamge prior up the image been uploaded to the server.
I have a user form which allows the selection of an image from a local drive. The form gets submitted and my upload script runs.
The error I am getting is,
Warning: imagecreatefrompng(Untitled-5.png) [function.imagecreatefrompng]: failed to open stream: No such file or directory in /home/xxxxx/public_html//new_upload.php on line 275
I am I using the "$_FILES['image_field']['name']" correctly.
The user form:
<form action="new_upload.php" target="_self" method="post" enctype="multipart/form-data" name="new" id="new">
<input type="image" src="../../../nav/images/save_button.png" class="submit" value="upload"/>
<input type="file" name="image_field" id="image_field" class="imaindatesel"/>
</form.
In the upload script I have:
$img = imagecreatefrompng($_FILES['image_field']['name']);
//find the size of the borders
$b_top = 0;
$b_btm = 0;
$b_lft = 0;
$b_rt = 0;
//top
for(; $b_top < imagesy($img); ++$b_top) {
for($x = 0; $x < imagesx($img); ++$x) {
if(imagecolorat($img, $x, $b_top) != 0xFFFFFF) {
break 2; //out of the 'top' loop
}
}
}
//bottom
for(; $b_btm < imagesy($img); ++$b_btm) {
for($x = 0; $x < imagesx($img); ++$x) {
if(imagecolorat($img, $x, imagesy($img) - $b_btm-1) != 0xFFFFFF) {
break 2; //out of the 'bottom' loop
}
}
}
//left
for(; $b_lft < imagesx($img); ++$b_lft) {
for($y = 0; $y < imagesy($img); ++$y) {
if(imagecolorat($img, $b_lft, $y) != 0xFFFFFF) {
break 2; //out of the 'left' loop
}
}
}
//right
for(; $b_rt < imagesx($img); ++$b_rt) {
for($y = 0; $y < imagesy($img); ++$y) {
if(imagecolorat($img, imagesx($img) - $b_rt-1, $y) != 0xFFFFFF) {
break 2; //out of the 'right' loop
}
}
}
//copy the contents, excluding the border
$newimg = imagecreatetruecolor(
imagesx($img)-($b_lft+$b_rt), imagesy($img)-($b_top+$b_btm));
imagecopy($newimg, $img, 0, 0, $b_lft, $b_top, imagesx($newimg), imagesy($newimg));
//finally, output the image
header("Content-Type: image/jpeg");
imagejpeg($newimg);
echo imagejpeg;