Jump to content

Image resize without using GD


vbnullchar

Recommended Posts

Yes but its a hell of a lot of work :)

One method is to; Write the image parsers yourself, which would mean handling binary data inside your script... this also means you'd need to also write/use a zip decompressor/compressor if you wanted to I/O PNGs.

Or you could search for other Perl/PHP Modules, possibly use ImageMagiK (sp?)

hth
Link to comment
Share on other sites

Do you have the [b]ImageMagick[/b] library installed on the server. In case you do, then the [b]convert command[/b] can be called from within php using [b]passthru function[/b] like this:

[code]passthru("/usr/bin/convert -resize 30x30 image.jpg -");[/code]

this will output the thumbnail of size 30x30 to the browser. image.jpg should be an image file on the disk.
Link to comment
Share on other sites

[quote author=Vikas Jayna link=topic=114369.msg465394#msg465394 date=1163071834]
Do you have the [b]ImageMagick[/b] library installed on the server. In case you do, then the [b]convert command[/b] can be called from within php using [b]passthru function[/b] like this:

[code]passthru("/usr/bin/convert -resize 30x30 image.jpg -");[/code]

this will output the thumbnail of size 30x30 to the browser. image.jpg should be an image file on the disk.
[/quote]

What if my image is stored in a MySQL database base64 encoded?
Link to comment
Share on other sites

decode the image with [b]base64_decode()[/b] and then write it to a temporary file on the disk (say image.jpg). In case you do not wish to write the file on the disk, then the code would look something like this:

[code]$fp=popen("/usr/bin/convert -resize 30x30 - -");
fwrite($fp,$imagecontent);
pclose($fp);[/code]

Here the command uses an additional [b]hyphen[/b] which means that the input image will come from standard input stream i.e. the content writen by [b]fwrite[/b] function
Link to comment
Share on other sites

If the images come from a recent digital camera, you may be able to use one of the [url=http://www.php.net/exif]exif[/url] functions, especially the [url=http://www.php.net/exif_thumbnail]exif_thumbnail()[/url] function which extracts the embedded thumbnail from the full size picture.

Ken
Link to comment
Share on other sites

[code]
<?php
function imageResize($width, $height, $target) {

if ($width > $height) {
$percentage = ($target / $width);
} else {
$percentage = ($target / $height);
}

//gets the new value and applies the percentage, then rounds the value
$width = round($width * $percentage);
$height = round($height * $percentage);

//returns the new sizes in html image tag format...this is so you
//can plug this function inside an image tag and just get the
return "width=\"$width\" height=\"$height\"";
}
$pic = "./images/picture.jpg";
$mysock = getimagesize($pic);
$var = imageResize($mysock[0], $mysock[1], 150);
?>

<img src="<?=$pic?>" <?=$var?>>
[/code]

It worked for me promise. It feels good to help someone. I have learned the hard way when I'm still starting as a PHP Developer.
Link to comment
Share on other sites

[quote author=heckenschutze link=topic=114369.msg466406#msg466406 date=1163230963]
The image is still going to have the same size, byte wise...

Not sure that's what he's after. :)
[/quote]
Yes you are correct. Same size but in thumbnail view. For example resize it by minus 25% but same size
Link to comment
Share on other sites

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.