English 中文(简体)
与各种图像文件类型合作( 并保存)?
原标题:Working with (and saving) various image filetypes?

我正在制作一个刻录图像的脚本。 它正在对 jpgs 工作 。 但是, 是否有一种方法可以将其应用到各种文件类型( bmp、 png、 gif) 的“ 坚固” 上, 没有 " / 坚固 ", 正在经历各种条款?

//create the crop
// Original image
$filename =  uploads/ .$image_name;

$endname =  uploads/thumbnails/ .$image_name;

// Get dimensions of the original image
list($current_width, $current_height) = getimagesize($filename);

// The x and y coordinates on the original image where we
// will begin cropping the image
$left = 0;
$top = 0;

// This will be the final size of the image (e.g. how many pixels
// left and down we will be going)
$crop_width = 200;
$crop_height = 200;

// Resample the image
$canvas = imagecreatetruecolor($crop_width, $crop_height);
$current_image = imagecreatefromjpeg($filename);
imagecopy($canvas, $current_image, 0, 0, $left, $top, $crop_width, $crop_height);
imagejpeg($canvas, $endname, 100);

我尝试用 imagecreate 替换 imcreate fromjpeg , 替换为 imagecreate , 但无效 。

最佳回答

< a href=" "http://php.net/ manual/ en/ opident. image create fromstring.php" rel = "nofollow"\\ code> imagecreate fromstring 自动检测文件类型,但它需要图像数据作为字符串,但您可以总是这样做。

$current_image = imagecreatefromstring(file_get_contents($filename));
问题回答

scr - for your source files dest - for resulting files

     $size = getimagesize($src); 

        // Detect file format from MIME-information, detected by getimagesize() function
        // And select proper imagecreatefrom()-function.
$format = strtolower(substr($size[ mime ], strpos($size[ mime ],  / )+1));
$icfunc = "imagecreatefrom" . $format;
if (!function_exists($icfunc)){
    echo "Function $icfunc doesn t exists!");
}

    //Here is the magic: We call function, which name is value of variable
$isrc = $icfunc($src);

    // Create new img
$idest = imagecreatetruecolor($width_dest, $height_dest);

    // Copy src img to dest img with resizing
imagecopyresampled(
    $idest, $isrc,  // dest & src img ident
    0,0,      // dest img (x,y) top left corner
    0,0,      // src img (x,y) top left corner
    $width_dest, $height_dest,
    $width_src, $height_src
);




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签