Jump to content

Recommended Posts

I'm trying this simple script to resize an image, but it won't work.

The file keeps giving me this as output: ' http://localhost/res/cms/img.php '

Here's my script:

<?php 

$src = ImageCreateFromJPEG('1.jpg');
list($width,$height) = getimagesize($src);
$x = .5 * $width;
$y = .5 * $height;
$dst = ImageCreateTrueColor($x,$y);
ImageCopyResampled($dst,$src,0,0,0,0,$x,$y,$width,$height);
header('Content-Type: image/jpeg');
imagejpeg($dst);
?>

Link to comment
https://forums.phpfreaks.com/topic/52723-solved-easy-resizing-image-problem/
Share on other sites

if that file above is "img.php"

 

then, in another page, put

 

<img src="img.php">

 

to display the resized image.

 

 

And don't forget to

 

imagedestroy($src);

imagedestroy($dst);

 

at the end of img.php to release the memory.

When displaying it with HTML, couldn't you set the width and height to the appropriate values?

 

-Brandon

still get a broken image. I'd rather resize the image.

comment out the header() statement and call it direct. see if it gives an error

 

Still nothing, all I get is a broken image sign in IE, and nothing in FF.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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