Ja topic sier vel sitt, trenger hjelp til hvordan jeg kan hente informasjon om et bilde via curl?
Noen som kan hjelpe meg med det?
Noen som kan hjelpe meg med det?
11
860
|
[IMG]url[/img]
<?php function replaceIMG ($text) { global $get; if (preg_match_all("#<img src=\"(.+?)\">#im",$text, $imgs)) { $y = 0; foreach ($imgs[0] AS $String) { $type = explode(".", "{$imgs[1][$y]}"); $count = count($type); for ($i = 0; $i < $count; $i++) { if ($i == ($count - 1)) { $type = $type[$i]; } } $type = strtolower($type); if (preg_match("/(http:\/\/)/si", $imgs[1][$y]) && preg_match("/(gif|jpg|jpeg|png)$/si", $type)) { $ch = curl_init(); $set = curl_setopt($ch, CURLOPT_URL,$imgs[1][$y]); $set .= curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $set .= curl_setopt ($ch, CURLOPT_HTTPHEADER, array("Content-Type: image/gif")); $resultat = curl_exec ($ch); $ch .= curl_close ($ch); $filename = randomkeys(32) . "." . $type; $url = "user/".$filename; file_put_contents($url,$resultat, FILE_APPEND | LOCK_EX); $unlink = 1; } else { $url = $imgs[1][$y]; $unlink = 0; } if ($type == "jpg") { $srcImg = @imagecreatefromjpeg($url); } elseif ($type == "gif") { $srcImg = @imagecreatefromgif($url); } elseif ($type == "png") { $srcImg = @imagecreatefrompng($url); } if ($get == '15') $max = 400; else $max = 515; if ($type == "jpg" || $type == "gif" || $type == "png") { $origWidth = @imagesx($srcImg); $origHeight = @imagesy($srcImg); if ($origWidth > $origHeight) { if ($origWidth < $max ) { $thumbHeight = $origHeight; $thumbWidth = $origWidth; } else { $ratio = $origWidth / $max; $thumbHeight = floor($origHeight / $ratio); $thumbWidth = floor($max); } } else { if ($origHeigt < $max ) { $thumbHeight = $origHeight; $thumbWidth = $origWidth; } else { $ratio = $origHeight / $max; $thumbWidth = floor($origWidth / $ratio); $thumbHeight = floor($max); } } } if ($unlink == 1) unlink($url); $text = str_replace($String, "<img src=\"{$imgs[1][$y]}\" style=\"width: ".$thumbWidth."px; height: ".$thumbHeight."px;\" />", $text); $y++; $thumbHeight = ""; $thumbWidth = ""; } } return $text; } ?>
|