Php scaling image (proportional scaling based on width and height) instance introduction _ PHP Tutorial

Source: Internet
Author: User
Php scaling image (proportional scaling based on width and height) example. Recommended a simple and practical image scaling tool SimpleImage, reference www. white-hat-web-design.co.ukblogresizing-images-with-php use method: set the width and height, unequal proportional scaling recommended a simple and practical image scaling tool SimpleImage, refer to the http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/

Usage:

Set width and height, and scale proportionally

The code is as follows:


Include ('simpleimage. php ');
$ Image = new SimpleImage ();
$ Image-> load('picture.jpg ');
$ Image-> resize( 250,400 );
$ Image-> save('picture2.jpg ');?>

Set width and proportional scaling

Include ('simpleimage. php ');
$ Image = new SimpleImage ();
$ Image-> load('picture.jpg ');
$ Image-> resizeToWidth (250 );
$ Image-> save('picture2.jpg ');?>

Set height, proportional scaling

Include ('simpleimage. php ');
$ Image = new SimpleImage ();
$ Image-> load('picture.jpg ');
$ Image-> resizeToHeight (500 );
$ Image-> save('picture2.jpg ');
$ Image-> resizeToHeight (200 );
$ Image-> save('picture3.jpg ');?>

Scale to 50% in proportion

Include ('simpleimage. php ');
$ Image = new SimpleImage ();
$ Image-> load('picture.jpg ');
$ Image-> scale (50 );
$ Image-> save('picture2.jpg ');?>

Scale and output directly to the screen

Header ('content-Type: image/jpeg ');
Include ('simpleimage. php ');
$ Image = new SimpleImage ();
$ Image-> load('picture.jpg ');
$ Image-> resizeToWidth (150 );
$ Image-> output ();?>


SimpleImage. php source code. click the link at the beginning of the article to download it.

SimpleImage, refer to http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/ usage: set width and height, proportional scaling...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.