Wrox Programmer Forums
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 19th, 2005, 06:25 AM
cli cli is offline
Authorized User
 
Join Date: May 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default Work with Image

Hi to all i need a little help.
I 've a script that I use to resize image with imagecreatefromjpeg() and imagecreatetruecolor()

I've se that i can pass to the scripts the Width and Height of the image 'till here no problem i've got amy image now i want to resize only the width of an image, how i can do this whit out compromising the porpotion of the image????

 
Old July 19th, 2005, 06:04 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Use something like this.
Code:
        function image_resize_to_ratio($image_location, $thumb = false)
        {

            if ($thumb == false)
            {
                $maximum_width  = (empty($this->resize_width))?  $this->width  : $this->resize_width;
                $maximum_height    = (empty($this->resize_height))? $this->height : $this->resize_height;
            }
            else
            {
                $maximum_height = $this->tmb_height;
                $maximum_width    = $this->tmb_width;
            }

            $size = @getimagesize($image_location);

                if (empty($size))
                {
                    library::error("Error: image location (".$image_location.") did not yield a valid image in file:".__FILE__." @ Line: ".__LINE__);
                    return false;
                }

            $this->actual_width     = $size[0];
            $this->actual_height    = $size[1];

            $x_ratio = $maximum_width / $this->actual_width;
            $y_ratio = $maximum_height / $this->actual_height;

            if (($this->actual_width <= $maximum_width) && ($this->actual_height <= $maximum_height))
            {
                $this->resize_width     = $this->actual_width;
                $this->resize_height = $this->actual_height;
            }
            else if (($x_ratio * $this->actual_height) < $maximum_height)
            {
                $this->resize_height = ceil($x_ratio * $this->actual_height);
                $this->resize_width     = $maximum_width;
            }
            else
            {
                $this->resize_width     = ceil($y_ratio * $this->actual_width);
                $this->resize_height = $maximum_height;
            }

            return;
        }
That's a function from an old library of mine that finds the correct width and height with respect to the aspect ratio when resizing an image. I'll leave it to you to figure out the logic and modify the code to how you need it.

HTH!

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design





Similar Threads
Thread Thread Starter Forum Replies Last Post
Upload image-create & save thumbnail-display image angshujit ASP.NET 2.0 Professional 6 July 11th, 2013 10:34 PM
Copy kodak image edit control's image to clipboard vishwanathduddilla Visual Studio 2005 0 November 3rd, 2008 10:10 AM
set image on <asp:Image> stored in DataBase myself.panku ASP.NET 2.0 Professional 1 August 11th, 2008 10:41 AM
Default image generation while uploading an image! ostwald ASP.NET 2.0 Professional 1 September 12th, 2007 01:44 AM
Document Image Processing (DIP) - changing image f ALcom Access 0 March 27th, 2006 06:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.