php高效快速获取图片尺寸的方法
在 php 获取图片尺寸的方法我们可以使用 getimagesize 获取图片尺寸的效率是很低的,首先需要获取整个的图片信息,然后再进行操作,下面的例子更科学算法更好,我们一起来看看吧。
下方法可以用于快速获取图片尺寸信息
1.获取JPEG格式图片的尺寸信息
<?php /* * 获取JPEG格式图片的尺寸信息,并且不需要下载/读取整个图片。 * 经测试这个函数不是对所有JPEG格式的图片都有效。 * http://www.phprm.com */ // Retrieve JPEG width and height without downloading/reading entire image. function getjpegsize($img_loc) { $handle = fopen($img_loc, "rb") or die("Invalid file stream."); $new_block = NULL; if(!feof($handle)) { $new_block = fread($handle, 32); $i = 0; if($new_block[$i]=="xFF" && $new_block[$i+1]=="xD8" && $new_block[$i+2]=="xFF" && $new_block[$i+3]=="xE0") { $i += 4; if($new_block[$i+2]=="x4A" && $new_block[$i+3]=="x46" && $new_block[$i+4]=="x49" && $new_block[$i+5]=="x46" && $new_block[$i+6]=="x00") { // Read block size and skip ahead to begin cycling through blocks in search of SOF marker $block_size = unpack("H*", $new_block[$i] . $new_block[$i+1]); $block_size = hexdec($block_size[1]); while(!feof($handle)) { $i += $block_size; $new_block .= fread($handle, $block_size); if($new_block[$i]=="xFF") { // New block detected, check for SOF marker $sof_marker = array("xC0", "xC1", "xC2", "xC3", "xC5", "xC6", "xC7", "xC8", "xC9", "xCA", "xCB", "xCD", "xCE", "xCF"); if(in_array($new_block[$i+1], $sof_marker)) { // SOF marker detected. Width and height information is contained in bytes 4-7 after this byte. $size_data = $new_block[$i+2] . $new_block[$i+3] . $new_block[$i+4] . $new_block[$i+5] . $new_block[$i+6] . $new_block[$i+7] . $new_block[$i+8]; $unpacked = unpack("H*", $size_data); $unpacked = $unpacked[1]; $height = hexdec($unpacked[6] . $unpacked[7] . $unpacked[8] . $unpacked[9]); $width = hexdec($unpacked[10] . $unpacked[11] . $unpacked[12] . $unpacked[13]); return array($width, $height); } else { // Skip block marker and read block size $i += 2; $block_size = unpack("H*", $new_block[$i] . $new_block[$i+1]); $block_size = hexdec($block_size[1]); } } else { return FALSE; } } } } } return FALSE; } ?>
2.
$url='http://www.phprm.com /images/201203/08/1331189004_28093400.jpg'; $image_content = file_get_contents($url); $image = imagecreatefromstring($image_content); $width = imagesx($image); $height = imagesy($image); echo $width.'*'.$height."nr";
文章网址:
随意转载^^但请附上教程地址。

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











PHPWarning:fopen():SSLOperationfailedinfile.phponlineX 해결 방법 PHP 프로그래밍에서는 fopen 함수를 사용하여 파일이나 URL을 열고 관련 작업을 수행하는 경우가 많습니다. 그러나 fopen 함수를 사용할 때 때때로 Warning:fopen():SSLOperationfailedinfile.p와 유사한 문제가 발생할 수 있습니다.

PHPWarning:fopen():failedtoopenstream:Nosuchfileordirectory 해결 방법 PHP 개발을 사용하는 과정에서 "PHPWarning:fopen():failedtoopenstream:Nosuchfileordirectory"와 같은 파일 작업 문제가 종종 발생합니다.

PHPWarning:fopen():failedtoopenstream:Permissiondenied 문제 해결 방법 PHP 프로그램을 개발하는 과정에서 PHPWarning:fopen():failedtoopenstream:Permissiondenied와 같은 오류 메시지를 자주 접하게 됩니다. 이 오류는 일반적으로 잘못된 파일 또는 디렉터리 권한으로 인해 발생합니다.

Matlab에서 fopen 함수는 파일을 열고 파일에 대한 후속 읽기 또는 쓰기 작업을 위해 파일 식별자를 반환하는 데 사용됩니다. 필요에 따라 적절한 권한 옵션을 선택하여 파일을 열고 작업이 완료되면 즉시 파일을 닫습니다. 파일을 연 후에는 시스템 리소스를 해제하는 데 더 이상 필요하지 않은 시간에 파일이 닫히는지 확인해야 합니다. 또한 파일 열기에 실패하거나 작업 오류가 발생하는 경우 오류 처리 메커니즘을 사용하여 그에 따라 처리할 수 있습니다.

PHP 개발에서는 파일 작업이 매우 일반적입니다. 정상적인 상황에서는 파일 읽기, 쓰기, 삭제 및 기타 작업을 수행해야 합니다. 그 중 fopen 함수, fread 함수를 사용하여 파일을 읽을 수 있고, fopen 함수, fwrite 함수, fclose 함수를 사용하여 파일을 쓸 수 있습니다. 이 기사에서는 PHP가 fopen, fwrite 및 fclose를 사용하여 파일 작업을 수행하는 방법을 소개합니다. 1. fopen 함수 fopen 함수는 파일을 여는 데 사용됩니다. r은 다음과 같습니다.

C의 fopen() 메소드는 지정된 파일을 여는 데 사용됩니다. 문제 구문 FILE*fopen(filename,mode)을 이해하기 위해 예를 들어 보겠습니다. 다음은 fopen()을 사용하여 파일을 여는 데 유효한 모드입니다: 'r', 'w', 'a', 'r+', 'w+ ', 'a+'. 자세한 내용은 C 라이브러리 함수 fopen()을 참조하세요.

PHPWarning:fopen():failedtoopenstream:Nosuchfileordirectoryinfile.phponlineX를 해결하는 방법 PHP 프로그램을 개발하고 실행할 때 때때로 PHPWarning:fopen():failedtoopenstream:Nosuchfileor가 발생합니다.

PHP에서 fopen 함수의 사용법은 "fopen(filename, mode, include_path, context)"입니다. fopen() 함수는 파일이나 URL을 여는 데 사용됩니다. 실패하면 오류 메시지와 함께 false를 반환합니다.
