简体   繁体   中英

How to zoom image using php

There is any possibility to zoom an image in php? I've searched on google but nothing util found.

If someone has any tips please give it to me. Thank you

If you follow the imagecopyresampled php example (and make it large instead of smaller - (smaller is demonstrated in the php.net example), and if you are PASSING a js variable, then you would get something like the following php:

<?php
// The file
$imgin = $_POST["dogimg"];  
      //e.g if your img is called dogimg!
$percent = 1.4; //140%

// Content type
header('Content-Type: image/jpeg');

// Get new dimensions
list($width, $height) = getimagesize($imgin);
$new_width = $width * $percent;
$new_height = $height * $percent;

// Resample
$image_out = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($imgin);
imagecopyresampled($image_out, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

// Output
imagejpeg($image_out, null, 100);
?>

However, I should point out that you should be careful when working with file types such as images and I would advise that you put in some error handling to check that the file is an image at the start (preferably when you upload the image to begin with, if you are uploading the images via a website).

If you're working with pre-uploaded images that you have uploaded on the server, then you should be good to go.

use imagemagic

$geometry = '142x106';
$resize_geo = $geometry.'^';
$crop_geo = $geometry.'+0+0';
`convert $pic_original_path -resize $resize_geo -gravity Center -crop $crop_geo $pic_resized_path`;

Imagecopyresampled solution here:

$zoom=120; //to zoom 120%
$width = imagesx($myimage);
$height = imagesy($myimage);

$new_width = $width * $zoom / 100;
$new_height = $height * $zoom / 100;

imagecopyresampled($image_p, $myimage, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM