URL and Link repository

Friday, November 14, 2014

My PHP Code for Resizing Images into a Second Directory.

function compress_image($orig_url, $new_url, $quality) {
$info = getimagesize($orig_url);
if ($info['mime'] == 'image/jpeg') 
$image = imagecreatefromjpeg($orig_url);
elseif ($info['mime'] == 'image/gif') 
$image = imagecreatefromgif($orig_url);
elseif ($info['mime'] == 'image/png') 
$image = imagecreatefrompng($orig_url);
imagejpeg($image, $new_url, $quality);
return $new_url;
}
$sql = "SELECT
`idtags` as `id`,
`lat`,
`lng`,
`height` as `elevation`,
`title` as `title`,
 '0' as `distance`,
 '1' as `has_detail_page`, 
`url` as `url`,
`created` as `when`,
`private` as `priv`
FROM `tags` order by `created` desc;";
$result = mysql_query($sql) or trigger_error 
('JSON download error'.mysql_error(),E_USER_ERROR);
for ($i = 0; $i < mysql_num_rows($result); $i++){
$row = mysql_fetch_array($result);
$imgUrl = $row['url'];
$title = $row['title'];
$url = str_replace("%3A",":", $imgUrl);
$url2 = str_replace("%2F","/",$url);
$name = substr($url2, 29);
$url4 = "myNewImageFolder/".$name;
compress_image($url2, $url4, 75);
}

No comments:

Post a Comment