i got very hight resolution images . i would like to resize it to 800 with 600 px without using image editor is there anything like this on php something simple
i got very hight resolution images . i would like to resize it to 800 with 600 px without using image editor is there anything like this on php something simple
please help..
Yup, i have a code that should work just fine for you - providing you have a website or winamp on localhost, or something.
percent = if this is defined, image is resized by it's
value in percent (i.e. 50 to divide by 50 percent)
w = image width
h = image height
constrain = if this is parameter is passed and w and h are set
to a size value then the size of the resulting image
is constrained by whichever dimension is smaller
Requires the PHP GD Extension
Outputs the resulting image in JPEG Format
By: Michael John G. Lopez - www.sydel.net
Filename : imgsize.php
*/
if ($percent > 0) {
// calculate resized height and width if percent is defined
$percent = $percent * 0.01;
$w = $sw * $percent;
$h = $sh * $percent;
} else {
if (isset ($w) AND !isset ($h)) {
// autocompute height if only width is set
$h = (100 / ($sw / $w)) * .01;
$h = @round ($sh * $h);
} elseif (isset ($h) AND !isset ($w)) {
// autocompute width if only height is set
$w = (100 / ($sh / $h)) * .01;
$w = @round ($sw * $w);
} elseif (isset ($h) AND isset ($w) AND isset ($constrain)) {
// get the smaller resulting image dimension if both height
// and width are set and $constrain is also set
$hx = (100 / ($sw / $w)) * .01;
$hx = @round ($sh * $hx);
$im = @ImageCreateFro mJPEG ($img) or // Read JPEG Image
$im = @ImageCreateFro mPNG ($img) or // or PNG Image
$im = @ImageCreateFro mGIF ($img) or // or GIF Image
$im = false; // If image is not JPEG, PNG, or GIF
if (!$im) {
// We get errors from PHP's ImageCreate functions...
// So let's echo back the contents of the actual image.
readfile ($img);
} else {
// Create the resized image destination
$thumb = @ImageCreateTru eColor ($w, $h);
// Copy from image source, resize it, and paste to image destination
@ImageCopyResam pled ($thumb, $im, 0, 0, 0, 0, $w, $h, $sw, $sh);
// Output resized image
@ImageJPEG ($thumb);
}
??
[/code]
call a photo as <img src="imgsize.ph p?h=height__you _want&img=path_ to_image" />
this is not working my image name is foto1.jpg i am replacing it with image path butt i am not reciving anything can you tell my more clearly what should i do
this is not working my image name is foto1.jpg i am replacing it with image path butt i am not reciving anything can you tell my more clearly what should i do
Perhaps, rather than providing complete code, it would make more sense if you read up the documentation to understand exactly how such code functions. PHP is documented extremely well and it's easy to search and for questions such as this, it should be your first stop, before asking others.
You have two choices for image resizing in PHP. A simple resize (which can leave an image looking ugly), or resizing and resampling. The latter is likely what you want. Read about it here:
As Steven rightfully pointed out, providing the complete code to solve your problem will be less helpful in the long run than pointing you in the right direction so you can solve it yourself.
(Please keep that in mind when posting in the future, Markus.)
Using the links Steven provided and the code Markus posted you should be able to device a solution to this. This is a common problem so there should be plenty of documentation.
Try solving this yourself and post back if you are having any difficulties.
hey thnx for help . looks like i have problem with my local php server when i am runing the script i am reciving this error
Fatal error: Call to undefined function: imagecreatefrom jpeg() in D:\Sport's\3901 \3901\html\imgs ize.php on line 28
but when i have uploaded the scipt in my web server it was working do you have any idea why i am reciving this error ???
You will need GD to use the Image functions. Perhaps you have the module and simply need to edit your php.ini to enable it. Have a look in your config file.
Comment