hi.....i have this script (below #1) that is linked to another php file SimpleImage.php (#2) im trying to get it to work on my uploaded images but it keeps coming up errors.....i haven't altered anything except for:
$image->load('picture.jpg');
$image->resize(546,403);
$image->save('picture2.jpg');
I put the variables i need in there within " " instead of ' ' and i always get a error message.....am i doing something or cant this be used to the scale i require
#1 -
<?php
-
include('SimpleImage.php');
-
$image = new SimpleImage();
-
$image->load('picture.jpg');
-
$image->resize(546,403);
-
$image->save('picture2.jpg');
-
?>
-
#2 -
<?php
-
/*
-
* File: SimpleImage.php
-
* Author: Simon Jarvis
-
* Copyright: 2006 Simon Jarvis
-
* Date: 08/11/06
-
* Link: http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php
-
*
-
* This program is free software; you can redistribute it and/or
-
* modify it under the terms of the GNU General Public License
-
* as published by the Free Software Foundation; either version 2
-
* of the License, or (at your option) any later version.
-
*
-
* This program is distributed in the hope that it will be useful,
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-
* GNU General Public License for more details:
-
* http://www.gnu.org/licenses/gpl.html
-
*
-
*/
-
-
class SimpleImage {
-
-
var $image;
-
var $image_type;
-
-
function load($filename) {
-
$image_info = getimagesize($filename);
-
$this->image_type = $image_info[2];
-
if( $this->image_type == IMAGETYPE_JPEG ) {
-
$this->image = imagecreatefromjpeg($filename);
-
} elseif( $this->image_type == IMAGETYPE_GIF ) {
-
$this->image = imagecreatefromgif($filename);
-
} elseif( $this->image_type == IMAGETYPE_PNG ) {
-
$this->image = imagecreatefrompng($filename);
-
}
-
}
-
function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {
-
if( $image_type == IMAGETYPE_JPEG ) {
-
imagejpeg($this->image,$filename,$compression);
-
} elseif( $image_type == IMAGETYPE_GIF ) {
-
imagegif($this->image,$filename);
-
} elseif( $image_type == IMAGETYPE_PNG ) {
-
imagepng($this->image,$filename);
-
}
-
if( $permissions != null) {
-
chmod($filename,$permissions);
-
}
-
}
-
function output($image_type=IMAGETYPE_JPEG) {
-
if( $image_type == IMAGETYPE_JPEG ) {
-
imagejpeg($this->image);
-
} elseif( $image_type == IMAGETYPE_GIF ) {
-
imagegif($this->image);
-
} elseif( $image_type == IMAGETYPE_PNG ) {
-
imagepng($this->image);
-
}
-
}
-
function getWidth() {
-
return imagesx($this->image);
-
}
-
function getHeight() {
-
return imagesy($this->image);
-
}
-
function resizeToHeight($height) {
-
$ratio = $height / $this->getHeight();
-
$width = $this->getWidth() * $ratio;
-
$this->resize($width,$height);
-
}
-
function resizeToWidth($width) {
-
$ratio = $width / $this->getWidth();
-
$height = $this->getheight() * $ratio;
-
$this->resize($width,$height);
-
}
-
function scale($scale) {
-
$width = $this->getWidth() * $scale/100;
-
$height = $this->getheight() * $scale/100;
-
$this->resize($width,$height);
-
}
-
function resize($width,$height) {
-
$new_image = imagecreatetruecolor($width, $height);
-
imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
-
$this->image = $new_image;
-
}
-
}
-
?>
-
-
-
-
14 3686
well.....the error has stopped but it said that this was invalid
function getWidth() {
return imagesx($this->image);
}
function getHeight() {
return imagesy($this->image);
and it wasn't detecting the files i was pointing to with my variable....this is
$resizeM = "upload/imgtemp/m/$random_digit/$filename";
include('SimpleImage.php');
$image = new SimpleImage();
$image->load("$resizeM");
$image->resize(250,400);
$image->save("$resizeM");
thats the changes ive made
Looks like a problem with the path try:
And see what it outputs.
Also where is that script in relation to the uploads/ directory?
The error has now stopped? Is the image resizing working now then?
no it isn't resizing but it isn't giving me any errors.....its weird.....when i echo $resizeM i get the full location to the images that need resizing.
i'm going to think abaout this one and post again soon
Do you have error reporting on?
Nothing jumps out at me, but could you be uploading an image that isn't a JPEG, PNG or GIF?
error reporting is on and i have a set of test jpeg's that i am using to upload.
it's strange how it comes up with no errors at all but doesnt resize anything. I can't seem to figure this out
would it be better or easier to try resize the images during the upload process?
this is the coding i made to upload my files with.....can it be adapted to resize the images on upload? -
<?
-
while(list($key,$value) = each($_FILES['images']['name']))
-
{
-
if(!empty($value))
-
{
-
$filename = $value;
-
$filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line
-
-
$add = "upload/imgtemp/m/$random_digit/$filename";
-
$tempFLDR = "upload/imgtemp/t/$random_digit/$filename";
-
//echo $_FILES['images']['type'][$key];
-
// echo "<br>";
-
copy($_FILES['images']['tmp_name'][$key], $add);
-
chmod("$add",0777);
-
copy($_FILES['images']['tmp_name'][$key], $tempFLDR);
-
chmod("$tempFLDR",0777);
-
-
$folderPath="upload/$random_digit/";
-
}
-
}
-
?>
-
wooohoooo i have got it to resize lol but errmmmm if i upload 1 image then it resizes fine but if i upload more than one image it only resizes the last image.
why does it do this....here is the code i have that is working for me -
<?
-
while(list($key,$value) = each($_FILES['images']['name']))
-
{
-
if(!empty($value))
-
{
-
$filename = $value;
-
$filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line
-
-
$add = "upload/imgtemp/m/$random_digit/$filename";
-
$tempFLDR = "upload/imgtemp/t/$random_digit/$filename";
-
//echo $_FILES['images']['type'][$key];
-
// echo "<br>";
-
copy($_FILES['images']['tmp_name'][$key], $add);
-
chmod("$add",0777);
-
copy($_FILES['images']['tmp_name'][$key], $tempFLDR);
-
chmod("$tempFLDR",0777);
-
-
$folderPath="upload/$random_digit/";
-
}
-
}
-
include('SimpleImage.php');
-
$image = new SimpleImage();
-
$image->load("$add");
-
$image->resize(250,400);
-
$image->save("$add");
-
?>
-
That's because your image manipulation happens outside of the while loop, meaning only the last image's path will be read. Move the include to the beginning of the file, and move the method calls to the end of the while loop.
like this? im still a newbie....sorry for the hassle -
<?
-
include('SimpleImage.php');
-
while(list($key,$value) = each($_FILES['images']['name']))
-
{
-
if(!empty($value))
-
{
-
$filename = $value;
-
$filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line
-
-
$add = "upload/imgtemp/m/$random_digit/$filename";
-
$tempFLDR = "upload/imgtemp/t/$random_digit/$filename";
-
//echo $_FILES['images']['type'][$key];
-
// echo "<br>";
-
copy($_FILES['images']['tmp_name'][$key], $add);
-
chmod("$add",0777);
-
copy($_FILES['images']['tmp_name'][$key], $tempFLDR);
-
chmod("$tempFLDR",0777);
-
-
$folderPath="upload/$random_digit/";
-
}
-
$image = new SimpleImage();
-
$image->load("$add");
-
$image->resize(546,403);
-
$image->save("$add");
-
}
-
-
?>
-
Thanks Markus!!!!! it works like a charm...i'll be back with a link once the finished product is done.
Thanks again
@anfetienne
Coolios, and you're welcome.
You don't need to recreate the object ($x = new x;) in the while loop - that'll use up more resources. So, just create the object after you include the class.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Alex Hopson |
last post by:
I'm using the code below to loop through some images and resize each image
twice, once to create a thumbnail and once to create a small image.
The page stops loading around the 38th image out of...
|
by: Clyde Ellul |
last post by:
Hi there.
I need to write a simple program that reads a GIF image from an input
stream, resizes it, then writes it back to an output stream in the
same format (GIF). (JPEG input/output is good...
|
by: riki |
last post by:
Hi,
i have a big problem...i'm using one jscript for resizing of all of my pics
in popUp...in main html i'm having many little pics and clicking on them
they open in popUp and resize to larger...
|
by: Jim |
last post by:
I've heard that resizing images through PHP (either GD2 or ImageMagick)
is a processor intensive exercise. I'm setting up a site where users
will be uploading up to 10 images along with the details...
|
by: Ron Vecchi |
last post by:
I am using asp.net to upload an image and then perform resizing on it and
saving the different sizes to file.
The resized images were coming up and being displayed in the bowser fine but
the image...
|
by: David W. Simmonds |
last post by:
I have a DataList control that has an Image control in the ItemTemplate. I
would like to resize the image that goes into that control. I have a series
of jpg files that are full size, full...
|
by: tomasio |
last post by:
Dear NG,
years have passed and I am still more designer than programmer. I
build a new version of my website which has a few nasty bugs,
especially on my startpage: Resizing text brakes the...
|
by: berkshire |
last post by:
Hi,
Anyone know of a script out there that can resize images and not
sacrifice image quality? I've been using phpthumb
(http://phpthumb.sourceforge.net/) but when compared to an image
resized...
|
by: mishrarajesh44 |
last post by:
hii all,
I am facing a problem currently..
i have a script for image uploading and resizing..
the image uploading takes place properly for every size images..
but, the resizing works for...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |