<?php if( !ini_get('safe_mode') ){ set_time_limit(500); } /* http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php http://www.codeartistique.com/2009/01/08/connaitre-le-poids-dun-fichier-distant-utile-en-php-4x.html */ /*tu peux enlever cette fonction c'est juste pour le poids ...*/ function Remote_Filesize($url) { $sch = parse_url($url, PHP_URL_SCHEME); if (($sch != "http") && ($sch != "https") && ($sch != "ftp") && ($sch != "ftps")) { return false; } if (($sch "http") || ($sch "https")) { $headers = @get_headers($url, 1); if (!is_array($headers)){$headers=array();} if ((!array_key_exists("Content-Length", $headers))) { return false; } return $headers["Content-Length"]; } if (($sch "ftp") || ($sch "ftps")) { $server = parse_url($url, PHP_URL_HOST); $port = parse_url($url, PHP_URL_PORT); $path = parse_url($url, PHP_URL_PATH); $user = parse_url($url, PHP_URL_USER); $pass = parse_url($url, PHP_URL_PASS); if ((!$server) || (!$path)) { return false; } if (!$port) { $port = 21; } if (!$user) { $user = "anonymous"; } if (!$pass) { $pass = "phpos@"; } switch ($sch) { case "ftp": $ftpid = ftp_connect($server, $port); break; case "ftps": $ftpid = ftp_ssl_connect($server, $port); break; } if (!$ftpid) { return false; } $login = ftp_login($ftpid, $user, $pass); if (!$login) { return false; } $ftpsize = ftp_size($ftpid, $path); ftp_close($ftpid); if ($ftpsize == -1) { return false; } return $ftpsize; } } /* * File: SimpleImage.php * Author: Simon Jarvis * Copyright: 2006 Simon Jarvis * Date: 08/11/06 * Link: http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details: * http://www.gnu.org/licenses/gpl.html * */ class SimpleImage { var $image; var $image_type; function load($filename) { $image_info = getimagesize($filename); $this->image_type = $image_info[2]; if( $this->image_type == IMAGETYPE_JPEG ) { $this->image = imagecreatefromjpeg($filename); } elseif( $this->image_type == IMAGETYPE_GIF ) { $this->image = imagecreatefromgif($filename); } elseif( $this->image_type == IMAGETYPE_PNG ) { $this->image = imagecreatefrompng($filename); } } function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) { if( $image_type == IMAGETYPE_JPEG ) { imagejpeg($this->image,$filename,$compression); } elseif( $image_type == IMAGETYPE_GIF ) { imagegif($this->image,$filename); } elseif( $image_type == IMAGETYPE_PNG ) { imagepng($this->image,$filename); } if( $permissions != null) { chmod($filename,$permissions); } } function output($image_type=IMAGETYPE_JPEG) { if( $image_type == IMAGETYPE_JPEG ) { imagejpeg($this->image); } elseif( $image_type == IMAGETYPE_GIF ) { imagegif($this->image); } elseif( $image_type == IMAGETYPE_PNG ) { imagepng($this->image); } } function getWidth() { return imagesx($this->image); } function getHeight() { return imagesy($this->image); } function resizeToHeight($height) { $ratio = $height / $this->getHeight(); $width = $this->getWidth() * $ratio; $this->resize($width,$height); } function resizeToWidth($width) { $ratio = $width / $this->getWidth(); $height = $this->getheight() * $ratio; $this->resize($width,$height); } function scale($scale) { $width = $this->getWidth() * $scale/100; $height = $this->getheight() * $scale/100; $this->resize($width,$height); } function resize($width,$height) { $new_image = imagecreatetruecolor($width, $height); imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight()); $this->image = $new_image; } } /*ton rep de stockage*/ $rep='mini'; if(file_exists($rep)){ }else{ mkdir($rep,chmod($rep, 755)); /*yo unix seulement*/ } /*1 à 25 faire une boucle */ $f='http://upload.wikimedia.org/wikipedia/commons/archive/3/3c/20090824120448!Nicolas_Sarkozy_(2008).jpg'; $i=explode('/',$f); $x=(count($i)-1); echo ''; print_r($i); echo ' '; echo $img=$i[$x]; $n=$rep.'/'.$img; if(file_exists($rep.'/'.$img)){ //on fait rien il existe }else{ //$file = file_get_contents ($f); /* echo ''; $r2=getimagesize($f); $r3=Remote_Filesize($f); print_r($r2); print_r($r3); echo ' OCTETS '; echo ' '; */ /*on redimensionne et enregistre*/ $image = new SimpleImage(); $image->load($f); $image->resizeToHeight(480); $image->save($n); echo 'reussi'; } ?>
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question<script> var pictureArchive= ['http://www.siteweb.fr','http://www.siteweb.fr']; window.onload=function() { var o=document.createElement('img'); o.setAttribute('id', 'image'); o.setAttribute('src', pictureArchive[0]); o.setAttribute('alt', ''); document.body.appendChild(o); rotate(pictureArchive.length); } function rotate(idx) { if(idx>=pictureArchive.length) { idx=0; } document.getElementById('image').src=pictureArchive[idx++]; timerID=setTimeout('rotate('+idx+')', 1000); } </script>