백엔드 개발 PHP 튜토리얼 PHP 폴더 순회, 동일한 비율의 이미지 압축

PHP 폴더 순회, 동일한 비율의 이미지 압축

Jul 25, 2016 am 08:42 AM

等比例, PHP
  1. /**
  2. * 출처 : 인터넷
  3. */
  4. 클래스 이미지
  5. {
  6. var $w_pct = 100; > var $w_quality = 100; //품질
  7. var $w_minwidth = 500; //최소 너비
  8. var $w_minheight = 500; //최소 높이
  9. //이미지입니다. 인터레이스
  10. var $fontfile; //글꼴 파일
  11. var $w_img; //기본 워터마크 이미지
  12. function __construct()
  13. {
  14. $this->fontfile = $_SERVER ['DOCUMENT_ROOT'].'/public/fonts/simhei.ttf';
  15. $this->w_img = ''
  16. }
  17. 함수 이미지()
  18. {
  19. $this ->__construct();
  20. }
  21. function info($img)
  22. {
  23. $imageinfo = getimagesize($img); //이미지 정보 배열 반환 0=> ;Width 픽셀 1=> 높이 픽셀 2=>는 이미지 유형입니다. 3 =>은 텍스트 문자열이고, 내용은 "height="yyy" width="xxx"",
  24. if($ imageinfo == = false) return false
  25. $imagetype = strtolower(substr(image_type_to_extension($imageinfo[2]),1)) //이미지 파일 형식 가져오기 $imageinfo[2]는 이미지 형식의 표시입니다
  26. $imagesize = filesize($img); //이미지 크기
  27. $info = array(
  28. 'width'=>$imageinfo[0],
  29. 'height'=>$imageinfo[1 ],
  30. 'type'=>$imagetype,
  31. 'size'=>$imagesize,
  32. 'mime'=>$imageinfo['mime']
  33. return $info
  34. }
  35. /**
  36. * 缩略图
  37. *
  38. * @param string $image
  39. * @param string $filename
  40. * @param int $maxwidth
  41. * @param int $maxheight
  42. * @param string $suffix
  43. * @param int $autocut
  44. * @return string
  45. */
  46. 함수 Thumb($image, $filename = '',$maxwidth = 50, $maxheight = 50, $suffix= '_thumb', $autocut = 0)
  47. {
  48. if( !$this->check($image)) return false
  49. $info = $this->info($image); //이미지 정보 가져오기
  50. if($info === false) return false
  51. $srcwidth = $info['width'] //소스 이미지 너비
  52. $srcheight = $info['height ']; //소스 이미지 높이
  53. $pathinfo = pathinfo($image);
  54. $type = $pathinfo['extension'] //확장자 가져오기
  55. if(!$type) $type = $info['type']; //얻지 못한 경우 $info['type'] 사용
  56. $type = strtolower($type)
  57. unset($info)
  58. $scale = min ($maxwidth/$srcwidth, $maxheight/$srcheight); //썸네일 비율 가져오기
  59. //소스 이미지에 따른 비율 가져오기
  60. $createwidth = $width = (int) ($srcwidth* $ scale);//썸네일 너비 가져오기();
  61. $createheight = $height = (int)($srcheight*$scale);//(); //썸네일 높이 가져오기
  62. $psrc_x = $ psrc_y = 0;
  63. if($autocut) //썸네일 비율에 따라
  64. 가져오기 {
  65. if($maxwidth/$maxheight<$srcwidth/$srcheight && $maxheight>=$height) // 썸네일이 원본 이미지보다 비례적으로 좁은 경우
  66. {
  67. $width = $maxheight/$height*$width; //해당 비율에 따라 너비가 처리됩니다.
  68. $height = $maxheight;/ //높이는 변경되지 않습니다
  69. }
  70. elseif($maxwidth/$maxheight>$srcwidth/$srcheight && $maxwidth>=$width)//썸네일이 소스 이미지보다 비례적으로 넓은 경우
  71. {
  72. $height = $maxwidth/$width*$height;//
  73. $width = $maxwidth;
  74. }
  75. if($maxwidth == '55'){
  76. $width = ' 55';
  77. $createwidth = '55';
  78. }
  79. if($maxwidth == '110'){
  80. $width = '110'
  81. $createwidth = '110' ;
  82. }
  83. }
  84. if($srcwidth<='280' && $maxwidth != '110'){
  85. $createwidth= $srcwidth
  86. $createheight; srcheight;
  87. }
  88. $createfun = 'imagecreatefrom'.($type=='jpg' ? 'jpeg' : $type) //다른 이미지 처리 함수 찾기
  89. $srcimg = $ createfun($ image); //이미지 식별자 반환
  90. if($type != 'gif' && function_exists('imagecreatetruecolor')){
  91. $thumbimg = imagecreatetruecolor($createwidth, $createheight); 컬러 이미지
  92. }else{
  93. if($maxwidth == '110' && $srcheight >= $srcwidth){
  94. $height1 = 72;
  95. $thumbimg = imagecreate($width, $height1); 팔레트 기반 이미지
  96. }elseif ($maxwidth == '110' && $srcheight <= $srcwidth){
  97. $width1 = 110; $thumbimg = imagecreate($width1, $ height) ; //새 팔레트 기반 이미지 생성
  98. }else{
  99. $thumbimg = imagecreate($width, $height) //새 팔레트 기반 이미지 생성
  100. }
  101. }
  102. if(function_exists('imagecopyresampled')){ //이미지의 복사본 부분을 리샘플링하고 크기를 조정합니다. 트루 컬러
  103. //imagecopyresampled(새 이미지, 원본 이미지, 새 이미지의 왼쪽 상단에서 x 거리, new 이미지 소스 이미지의 왼쪽 위 모서리로부터의 y 거리, 소스 이미지의 왼쪽 위 모서리로부터의 x 거리, 소스 이미지의 왼쪽 위 모서리로부터의 y 거리, 새 이미지 너비, 새 이미지 높이, 소스 이미지 너비, 소스 이미지 높이)
  104. if($maxwidth == '110' && $srcheight >= $srcwidth){
  105. $psrc_x = 0
  106. $psrc_yz = $height/2
  107. $psrc_y = $psrc_yz
  108. $width = '110';
  109. }
  110. if($maxwidth == '110' && $srcheight >= $srcwidth && $srcheight>= '72' && $srcwidth < = '110'){
  111. $psrc_x = 0;
  112. $ psrc_yz = $height/2;
  113. $psrc_y = $psrc_yz; > if($maxheight == '72' && $srcheight <= $srcwidth && $srcheight<= '72' && $srcwidth >= '110'){
  114. $cha = ($maxheight-$srcheight) /2; $psrc_y = -($cha);
  115. $height = '72'
  116. $srcheight = '72'; > imagecopyresampled($thumbimg, $srcimg, 0, 0, $psrc_x, $psrc_y , $width, $height, $srcwidth, $srcheight)
  117. }else{ //이미지의 일부를 복사하고 크기를 조정합니다. , 팔레트
  118. imagecopyreized($thumbimg, $srcimg, 0, 0, $psrc_x, $psrc_y, $width, $height, $srcwidth, $srcheight)
  119. }
  120. if($type==' gif' || $type=='png')
  121. {
  122. //imagecolorallocate는 이미지에 색상을 할당합니다
  123. $Background_color = imagecolorallocate($thumbimg, 0, 255, 0); 팔레트를 기준으로 이미지의 배경색을 녹색으로 지정합니다.
  124. // imagecolortransparent 색상을 투명 색상으로 정의합니다.
  125. imagecolortransparent($thumbimg, $Background_color) // 이 줄이 다음과 같은 경우 투명 색상으로 설정합니다. 주석 처리하면 녹색 이미지가 출력됩니다
  126. }
  127. // 이미지 인터레이스가 인터레이스를 활성화하거나 비활성화합니다
  128. if($type=='jpg' || $type=='jpeg') imageinterlace($thumbimg, $this->interlace);
  129. $imagefun = 'image'.($ type=='jpg' ? 'jpeg' : $type)
  130. //imagejpeg imagegif imagepng
  131. if(empty( $filename)) $filename = substr($image, 0, strrpos($image, ' .')).$suffix.'.'.$type; //파일 이름 가져오기
  132. //aaa.gif aaa_thumb. gif
  133. $imagefun($thumbimg, $filename); //새 이미지
  134. imagedestroy($thumbimg); //썸네일 삭제
  135. imagedestroy($srcimg); //소스 이미지 삭제
  136. return $ 파일 이름;
  137. }
  138. /**
  139. * 너비 또는 높이 제한
  140. *
  141. * @param string $image
  142. * @param int $maxwidth
  143. * @param int $maxheight
  144. * @param string $suffix
  145. * @return 문자열
  146. */
  147. function Thumb3($image,$maxwidth = 0, $maxheight = 0, $suffix='_thumb')
  148. {
  149. if( !$this->check($image)) return false
  150. $info = $this->info($image) //이미지 정보 가져오기
  151. if($info === false; ) return false
  152. $srcwidth = $info['width']; / /소스 이미지 너비
  153. $srcheight = $info['height'] //소스 이미지 높이
  154. $pathinfo = pathinfo( $image);
  155. $type = $pathinfo['extension']; / /확장자 가져오기
  156. if(!$type) $type = $info['type'] //얻지 못한 경우 $를 사용합니다. info['type']
  157. $type = strtolower($type) ;
  158. unset($info)
  159. if($maxwidth==0){
  160. $scale = $maxheight/$srcheight ;
  161. if($scale<1){
  162. $createwidth = $srcwidth*$scale
  163. $createheight = $maxheight; }else{
  164. $createwidth = $srcwidth; > $createheight = $srcheight
  165. }
  166. }
  167. if($maxheight==0){
  168. $scale = $maxwidth/$srcwidth
  169. if($scale<1){
  170. $createwidth = $maxwidth; > $createheight = $srcheight*$scale;
  171. }else{
  172. $createwidth = $srcwidth;
  173. $createheight = $srcheight;
  174. }
  175. }
  176. $psrc_x = $psrc_y = 0;
  177. $createfun = 'imagecreatefrom'.($type=='jpg' ? 'jpeg' : $type); //다른 이미지 처리 함수 찾기
  178. $srcimg = $createfun($image) ; //이미지 식별자 반환
  179. if($type != 'gif' && function_exists('imagecreatetruecolor')){
  180. $thumbimg = imagecreatetruecolor($createwidth, $createheight) //새 트루 컬러 이미지 생성;
  181. }else{
  182. $thumbimg = imagecreate($createwidth, $createheight); //새 팔레트 기반 이미지 생성
  183. }
  184. if(function_exists('imagecopyresampled')){ // 리샘플 이미지의 일부를 복사하고 크기 조정, 트루 컬러
  185. //imagecopyresampled(새 이미지, 원본 이미지, 새 이미지의 왼쪽 상단 모서리로부터의 x 거리, 새 이미지의 왼쪽 상단 모서리로부터의 y 거리, 원본 이미지의 x 거리 소스 이미지의 왼쪽 위 모서리, 소스 이미지의 왼쪽 위 모서리로부터 y 거리, 새 이미지 너비, 새 이미지 높이, 소스 이미지 너비, 소스 이미지 높이)
  186. imagecopyresampled($thumbimg, $srcimg, 0 , 0, $psrc_x, $psrc_y, $createwidth, $createheight, $srcwidth, $srcheight );
  187. }else{ //이미지의 일부를 복사하고 크기를 조정하고, 팔레트
  188. imagecopyreized($thumbimg, $srcimg, 0, 0, $psrc_x, $psrc_y, $createwidth, $createheight, $srcwidth, $srcheight)
  189. }
  190. if($type=='gif' || $type=='png ')
  191. {
  192. //imagecolorallocate는 이미지에 색상을 할당합니다.
  193. $Background_color = imagecolorallocate($thumbimg, 0, 255, 0) // 팔레트 기반 이미지를 배경색으로 채우고 할당합니다. 녹색
  194. // imagecolortransparent는 색상을 투명 색상으로 정의합니다.
  195. imagecolortransparent($thumbimg, $Background_color) // 이 줄을 주석 처리하면 녹색 이미지가 출력됩니다.
  196. }
  197. // 이미지 인터레이스는 인터레이스를 활성화하거나 비활성화합니다.
  198. if($type== 'jpg' || $type=='jpeg') imageinterlace($thumbimg, $this->interlace)
  199. $ imagefun = 'image'.($type=='jpg' ? 'jpeg' : $ type)
  200. //imagejpeg imagegif imagepng
  201. $filename = substr($image, 0, strrpos($image, ' .')).$suffix.'.'.$type; //파일 이름 가져오기
  202. //aaa.gif aaa_thumb.gif
  203. $imagefun($thumbimg, $filename); 🎜> imagedestroy($thumbimg); //썸네일 삭제
  204. imagedestroy($srcimg) ; //소스 이미지 삭제
  205. return $filename; 🎜> 정적 함수 Thumb2($image, $thumbname, $type='', $maxWidth= 200, $maxHeight=50, $interlace=true) {
  206. // 원본 이미지 정보 가져오기
  207. $info = Image ::getImageInfo($image);
  208. if ($info !== false) {
  209. $srcWidth = $info['width']
  210. $srcHeight = $info['height']; 🎜> $type = 비어 있음($type) ? $info['type'] : $type ;
  211. $type = strtolower($type)
  212. $interlace ? 1 : 0; unset($info);
  213. $scale = max($maxWidth / $srcWidth, $ maxHeight / $srcHeight); // 크기 조정 비율 계산
  214. // 원본 이미지와 썸네일 간의 비율을 판단합니다. 예를 들어 원본 이미지가 썸네일보다 넓은 경우 양쪽을 자르고 그 반대로도 자릅니다.
  215. if($maxWidth / $srcWidth > $ maxHeight / $srcHeight){
  216. //Higher than
  217. $ srcX = 0;
  218. $srcY = ($srcHeight - $maxHeight / $scale) / 2 ; $cutWidth = $srcWidth;
  219. $cutHeight = $maxHeight / $scale;
  220. //
  221. 보다 넓음 $srcX = ($srcWidth - $maxWidth / $scale) / 2;
  222. $srcY = 0
  223. $cutWidth = $maxWidth / $scale; 컷높이 = $srcHeight
  224. }
  225. // 载入原图
  226. $createFun = 'ImageCreateFrom' . ($type == 'jpg' ? 'jpeg' : $type);
  227. $srcImg = $createFun($image);
  228. //创建缩略图
  229. if ($type != 'gif' && function_exists('imagecreatetruecolor'))
  230. $thumbImg = imagecreatetruecolor($maxWidth, $maxHeight);
  231. else
  232. $thumbImg = imagecreate($maxWidth, $maxHeight);
  233. // 复제조그림
  234. if (function_exists("ImageCopyResampled"))
  235. imagecopyresampled($thumbImg, $srcImg, 0, 0, $srcX, $srcY, $maxWidth, $maxHeight, $ cutWidth, $cutHeight);
  236. else
  237. imagecopyreized($thumbImg, $srcImg, 0, 0, $srcX, $srcY, $maxWidth, $maxHeight, $cutWidth, $cutHeight);
  238. if ('gif' == $type || 'png' == $type) {
  239. //imagealphablending($thumbImg, false);//取消默认的混color模式
  240. //imagesavealpha( $thumbImg,true);//설정된 알파 통신
  241. $Background_color = imagecolorallocate($thumbImg, 0, 255, 0); // 指派一个绿color
  242. imagecolortransparent($thumbImg, $Background_color); // 设置为透밝은색,若注释掉该行则输流绿color的图
  243. }
  244. // 对jpeg图shape设置隔行扫描
  245. if ('jpg' == $type || ' jpeg' == $type)
  246. imageinterlace($thumbImg, $interlace);
  247. // 生成图文
  248. $imageFun = 'image' . ($type == 'jpg' ? 'jpeg' : $type);
  249. @chmod(dirname($thumbname),0777);
  250. $imageFun($thumbImg, $thumbname);
  251. imagedestroy($thumbImg);
  252. imagedestroy($srcImg);
  253. $thumbname을 반환합니다.
  254. }
  255. false를 반환합니다.
  256. }
  257. /**
  258. * 이미지 정보 가져오기
  259. * @static
  260. * @access public
  261. * @param string $image 이미지 파일 이름
  262. * @return 혼합
  263. */
  264. 정적 함수 getImageInfo($img) {
  265. $imageInfo = getimagesize($img);
  266. if ($imageInfo !== false) {
  267. $imageType = strtolower(substr(image_type_to_extension($imageInfo[2]), 1));
  268. $imageSize = 파일 크기($img);
  269. $info = array(
  270. "너비" => $imageInfo[0],
  271. "높이" => $imageInfo[1],
  272. "유형" => $imageType,
  273. "크기" => $imageSize,
  274. "mime" => $imageInfo['mime']
  275. );
  276. $정보 반환;
  277. } else {
  278. false를 반환합니다.
  279. }
  280. }
  281. //watermark(源图,生成文件,生成位置,水印文件,水印文本,背景color)
  282. function watermark($source, $target = '' , $w_pos = 9, $w_img = '', $w_text = '', $w_font = 12, $w_color = '#cccccc',$x='',$y='')
  283. {
  284. if( !$this->check($source)) return false;
  285. if(!$target) $target = $source;
  286. if ($w_img == '' && $w_text == '')
  287. $w_img = $this->w_img;
  288. $source_info = getimagesize($source);
  289. $source_w = $source_info[0]; //获取宽
  290. $source_h = $source_info[1]; //获取高
  291. if($source_w w_minwidth || $source_h w_minheight) return false; //宽和高达不到要求直接返回
  292. switch($source_info[2]) //새 페이지
  293. {
  294. 사례 1 :
  295. $source_img = imagecreatefromgif($source);
  296. 휴식;
  297. 사례 2 :
  298. $source_img = imagecreatefromjpeg($source);
  299. 휴식;
  300. 사례 3 :
  301. $source_img = imagecreatefrompng($source);
  302. 휴식;
  303. 기본값 :
  304. false를 반환합니다.
  305. }
  306. if(!empty($w_img) && file_exists($w_img)) //수印文件
  307. {
  308. $ifwaterimage = 1; //是否水印图
  309. $water_info = getimagesize($w_img); //수용성
  310. $width = $water_info[0];
  311. $height = $water_info[1];
  312. 스위치($water_info[2])
  313. {
  314. 사례 1 :
  315. $water_img = imagecreatefromgif($w_img);
  316. 휴식;
  317. 사례 2 :
  318. $water_img = imagecreatefromjpeg($w_img);
  319. 휴식;
  320. 사례 3 :
  321. $water_img = imagecreatefrompng($w_img);
  322. 휴식;
  323. 기본값 :
  324. 반환;
  325. }
  326. }
  327. else
  328. {
  329. $ifwaterimage = 0; //imagettfbbox(글꼴 크기, 글꼴 각도, 글꼴 파일, 파일)
  330. // echo $this->fontfile
  331. $temp = imagettfbbox(ceil($w_font*1.6), 0, $ this->fontfile, $w_text);//트루타입 글꼴을 사용하여 텍스트 범위 가져오기
  332. $width = $temp[4] - $temp[6] //오른쪽 위 모서리 X 위치 - 왼쪽 위 모서리 X position
  333. $height = $temp[3] - $temp[5]; //오른쪽 하단 Y 위치 - 오른쪽 상단 Y 위치
  334. unset($temp)
  335. }
  336. switch( $w_pos)
  337. {
  338. 사례 0: //임의의 위치
  339. $wx = rand(0,($source_w - $width))
  340. $wy = rand(0,($source_h - $height)) ;
  341. 중단;
  342. 사례 1: //왼쪽 상단
  343. $wx = 25;
  344. 중단; 상단 중간 위치
  345. $wx = ($source_w - $width) / 2;
  346. $wy = 0
  347. break
  348. 사례 3: //오른쪽 상단
  349. $wx = $ source_w - $width;
  350. $wy = 0;
  351. break;
  352. 사례 4: //왼쪽 중간 위치
  353. $wx = 0; height) / 2;
  354. break;
  355. 사례 5: //중간 위치
  356. $wx = ($source_w - $width) / 2; $wy = ($source_h - $height) / 2;
  357. break;
  358. 사례 6: //하단 중간 위치
  359. $wx = ($source_w - $width) / 2
  360. $wy = $source_h - $height; ;
  361. 사례 7: / /왼쪽 아래 모서리
  362. $wx = 0;
  363. $wy = $source_h - $height;
  364. break
  365. 사례 8: //오른쪽
  366. $wx = $source_w - $width ;
  367. $wy = ($source_h - $height) /2
  368. break;
  369. 사례 9: //오른쪽 하단
  370. $wx = $source_w - $width;
  371. $wy = $source_h - $height ;
  372. break;
  373. 기본값: //Random
  374. $wx = rand(0,($source_w - $width));
  375. $wy = rand(0,($ source_h - $height));
  376. break
  377. 케이스 10://맞춤 위치
  378. $wx = $x
  379. $wy; y;
  380. 사례 11: //하단 중간 위치--공예품 고객에게만 해당
  381. $wx = ($source_w - $width) / 2
  382. $wy = $source_h - $height-50; 🎜> break;
  383. break;
  384. }
  385. if($ifwaterimage) //워터마크 이미지가 있는 경우
  386. {
  387. //imagecopymerge는 이미지의 일부를 복사하고 병합합니다
  388. //매개변수(소스 이미지, 워터마크 이미지, 소스 이미지 x 위치로 복사, 소스 이미지 y 위치로 복사, 워터마크 이미지 x 위치, 워터마크 이미지 y 위치, 높이, 너비, 투명도)
  389. //imagecopymerge ($source_img, $water_img, $wx, $wy, 0, 0, $width, $height, $this->w_pct)
  390. imagecopy($source_img,$water_img,$wx,$wy ,0,0,$width,$height)
  391. }
  392. else
  393. {
  394. if(!empty($w_color) && (strlen($w_color)==7))
  395. {
  396. $r = hexdec(substr($w_color,1 ,2)); //빨간색 가져오기
  397. $g = hexdec(substr($w_color,3,2)) //녹색 가져오기
  398. $b = hexdec(substr($w_color,5)); / /Get blue
  399. }
  400. else
  401. {
  402. return
  403. }
  404. //imagecolorallocate 팔레트 기반 이미지 채우기 background color
  405. //imagestring은 가로로 선을 그립니다. String
  406. //imagestring(소스 이미지, 글꼴 크기, 위치 X, 위치 Y, 텍스트, 색상)
  407. //매개변수($image, float $size, float $angle, int $x, int $y , int $color, string $fontfile, string $text)
  408. imagettftext($source_img,$w_font,0,$wx,$wy,imagecolorallocate($source_img,$r) ,$g,$b),$this- >fontfile,$w_text)
  409. //imagestring($source_img,$w_font,$wx,$wy,$w_text,imagecolorallocate($source_img,$r,$ g,$b))
  410. }
  411. //輸出到檔案或瀏覽器
  412. switch($source_info[2])
  413. {
  414. case 1 :
  415. imagegif($source_img, $target); //以GIF 格式將影像輸出至瀏覽器或檔案
  416. break;
  417. case 2 :
  418. imagejpeg($source_img, $target, $this->w_quality); //以JPEG 格式將影像輸出到瀏覽器或檔案
  419. break;
  420. case 3 :
  421. imagepng($source_img, $target); //以PNG 格式將圖片輸出到瀏覽器或檔案
  422. break;
  423. default :
  424. return;
  425. }
  426. if(isset($water_info))
  427. {
  428. unset($water_info); //銷毀
  429. }
  430. if(isset($water_img))
  431. {
  432. imagedestroy($water_img); //銷毀
  433. }
  434. unset($source_info);
  435. imagedestroy($source_img);
  436. return true; //gd庫必須存在,後綴為jpg|jpeg|gif|png,文件存在,imagecreatefromjpeg或者imagecreatefromgif存在
  437. function check($image)
  438. {
  439. return extension_loaded('gd') &&
  440. preg_match("/.(JPG|JPEG|PNG|GIF|jpg|jpeg|gif|png)/i", $image, $m) &&
  441. file_exists($image) &&
  442. function_exists('imagecreatefrom '.($m[1] == 'jpg' ? 'jpeg' : $m[1]));
  443. //imagecreatefromjpeg
  444. //imagecreatefromgif
  445. //imagecreatefrompng
  446. }
  447. }
  448. /**
  449. 縮圖
  450. 1.新建一個圖像資源通過imagecreatefromgif imagecreatefromjpeg imagecreatefrompng
  451. 2.imagecopyresampled 拷貝圖片,並調整大小
  452. 水印:圖片
  453. 2.加浮水印
  454. 圖片浮水印:imagecopymerge 把2張圖合併在一起
  455. 文字浮水印:imagettftext 寫入文字
  456. */
  457. error_reporting(0);
  458. $hostdir = dirname(__FILE__);
  459. $filesnames = scandir($hostdir.'/desktop' );
  460. $img = new image();
  461. foreach($filesnames as $name){
  462. if($name != '.' && $name != '..'){
  463. $imgPath = $hostdir.'/desktop/';
  464. $imgsize = getimagesize($imgPath.$name);
  465. $imgInfo = explode('.',$name);
  466. $imginfo2 = explode('_',$imgInfo[0]);
  467. if($imginfo2[count($imginfo2)-1] != 'small'){
  468. $img_small = $imgPath.$imgInfo[0] .'_small.'.$imgInfo[1];
  469. $img->thumb2($imgPath.$name,$img_small,'',$imgsize[0]/4,$imgsize[1]/4);
  470. }
  471. }
  472. }
  473. 複製程式碼

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

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

AI Clothes Remover

AI Clothes Remover

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

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

Video Face Swap

Video Face Swap

완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

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

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

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

JWT (JSON Web Tokens) 및 PHP API의 사용 사례를 설명하십시오. JWT (JSON Web Tokens) 및 PHP API의 사용 사례를 설명하십시오. Apr 05, 2025 am 12:04 AM

JWT는 주로 신분증 인증 및 정보 교환을 위해 당사자간에 정보를 안전하게 전송하는 데 사용되는 JSON을 기반으로 한 개방형 표준입니다. 1. JWT는 헤더, 페이로드 및 서명의 세 부분으로 구성됩니다. 2. JWT의 작업 원칙에는 세 가지 단계가 포함됩니다. JWT 생성, JWT 확인 및 Parsing Payload. 3. PHP에서 인증에 JWT를 사용하면 JWT를 생성하고 확인할 수 있으며 사용자 역할 및 권한 정보가 고급 사용에 포함될 수 있습니다. 4. 일반적인 오류에는 서명 검증 실패, 토큰 만료 및 대형 페이로드가 포함됩니다. 디버깅 기술에는 디버깅 도구 및 로깅 사용이 포함됩니다. 5. 성능 최적화 및 모범 사례에는 적절한 시그니처 알고리즘 사용, 타당성 기간 설정 합리적,

세션 납치는 어떻게 작동하며 PHP에서 어떻게 완화 할 수 있습니까? 세션 납치는 어떻게 작동하며 PHP에서 어떻게 완화 할 수 있습니까? Apr 06, 2025 am 12:02 AM

세션 납치는 다음 단계를 통해 달성 할 수 있습니다. 1. 세션 ID를 얻으십시오. 2. 세션 ID 사용, 3. 세션을 활성 상태로 유지하십시오. PHP에서 세션 납치를 방지하는 방법에는 다음이 포함됩니다. 1. 세션 _regenerate_id () 함수를 사용하여 세션 ID를 재생산합니다. 2. 데이터베이스를 통해 세션 데이터를 저장하십시오.

확실한 원칙과 PHP 개발에 적용되는 방법을 설명하십시오. 확실한 원칙과 PHP 개발에 적용되는 방법을 설명하십시오. Apr 03, 2025 am 12:04 AM

PHP 개발에서 견고한 원칙의 적용에는 다음이 포함됩니다. 1. 단일 책임 원칙 (SRP) : 각 클래스는 하나의 기능 만 담당합니다. 2. Open and Close Principle (OCP) : 변경은 수정보다는 확장을 통해 달성됩니다. 3. Lisch의 대체 원칙 (LSP) : 서브 클래스는 프로그램 정확도에 영향을 미치지 않고 기본 클래스를 대체 할 수 있습니다. 4. 인터페이스 격리 원리 (ISP) : 의존성 및 사용되지 않은 방법을 피하기 위해 세밀한 인터페이스를 사용하십시오. 5. 의존성 반전 원리 (DIP) : 높고 낮은 수준의 모듈은 추상화에 의존하며 종속성 주입을 통해 구현됩니다.

시스템 재시작 후 UnixSocket의 권한을 자동으로 설정하는 방법은 무엇입니까? 시스템 재시작 후 UnixSocket의 권한을 자동으로 설정하는 방법은 무엇입니까? Mar 31, 2025 pm 11:54 PM

시스템이 다시 시작된 후 UnixSocket의 권한을 자동으로 설정하는 방법. 시스템이 다시 시작될 때마다 UnixSocket의 권한을 수정하려면 다음 명령을 실행해야합니다.

phpstorm에서 CLI 모드를 디버그하는 방법은 무엇입니까? phpstorm에서 CLI 모드를 디버그하는 방법은 무엇입니까? Apr 01, 2025 pm 02:57 PM

phpstorm에서 CLI 모드를 디버그하는 방법은 무엇입니까? PHPStorm으로 개발할 때 때때로 CLI (Command Line Interface) 모드에서 PHP를 디버그해야합니다 ...

PHP에서 늦은 정적 결합을 설명하십시오 (정적 : :). PHP에서 늦은 정적 결합을 설명하십시오 (정적 : :). Apr 03, 2025 am 12:04 AM

정적 바인딩 (정적 : :)는 PHP에서 늦은 정적 바인딩 (LSB)을 구현하여 클래스를 정의하는 대신 정적 컨텍스트에서 호출 클래스를 참조 할 수 있습니다. 1) 구문 분석 프로세스는 런타임에 수행됩니다. 2) 상속 관계에서 통화 클래스를 찾아보십시오. 3) 성능 오버 헤드를 가져올 수 있습니다.

PHP의 CURL 라이브러리를 사용하여 JSON 데이터가 포함 된 게시물 요청을 보내는 방법은 무엇입니까? PHP의 CURL 라이브러리를 사용하여 JSON 데이터가 포함 된 게시물 요청을 보내는 방법은 무엇입니까? Apr 01, 2025 pm 03:12 PM

PHP 개발에서 PHP의 CURL 라이브러리를 사용하여 JSON 데이터를 보내면 종종 외부 API와 상호 작용해야합니다. 일반적인 방법 중 하나는 컬 라이브러리를 사용하여 게시물을 보내는 것입니다 ...

See all articles