php Scale image of is an example of equal scale based on width and height

  • 2020-06-12 08:44:05
  • OfStack

Recommend a simple and practical zoom tool SimpleImage images, reference http: / / www white hat - web - design. co. uk/blog/resizing - images - with - php /

Usage:

Set the width and height and scale unequally
 
<?php 
include('SimpleImage.php'); 
$image = new SimpleImage(); 
$image->load('picture.jpg'); 
$image->resize(250,400); 
$image->save('picture2.jpg');?> 

 Set the width and scale accordingly 

<?php 
include('SimpleImage.php'); 
$image = new SimpleImage(); 
$image->load('picture.jpg'); 
$image->resizeToWidth(250); 
$image->save('picture2.jpg');?> 

 Set the height and scale equally 

<?php 
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%

<?php 
include('SimpleImage.php'); 
$image = new SimpleImage(); 
$image->load('picture.jpg'); 
$image->scale(50); 
$image->save('picture2.jpg');?>

 Zoom in and out directly to the screen 

<?php 
header('Content-Type: image/jpeg'); 
include('SimpleImage.php'); 
$image = new SimpleImage(); 
$image->load('picture.jpg'); 
$image->resizeToWidth(150); 
$image->output();?> 


SimpleImage.php source please click the link at the beginning of the article to download there

Related articles: