Monday, March 19, 2012

php - cropping an image

Basic way to implement a "crop" feature : given an image (src), an offset (x, y) and a size (w, h).

crop.php :
<?php
$w
=$_GET['w'];
$h=isset($_GET['h'])?$_GET['h']:$w;    // h est facultatif, =w par défaut
$x=isset($_GET['x'])?$_GET['x']:0;    // x est facultatif, 0 par défaut
$y=isset($_GET['y'])?$_GET['y']:0;    // y est facultatif, 0 par défaut
$filename=$_GET['src'];

$image = imagecreatefromjpeg($filename);
$crop = imagecreatetruecolor($w,$h);
imagecopy ( $crop, $image, 0, 0, $x, $y, $w, $h );
imagejpeg($crop,
$filename,100);
?>

Call it like this :

<img src="crop.php?x=10&y=20&w=30&h=40&src=photo.jpg">

Thursday, March 1, 2012

SQL to Create Sitemap

insert into posterdata_part1
select top 50000 *  from posterdata
order by PID

insert into posterdata_part2
select top 50000 *  from posterdata
where PID>(select max(PID) from #temp_part1)
order by PID

insert into posterdata_part3
select top 50000 *  from posterdata
where PID>(select max(PID) from #temp_part2)
order by PID


insert into posterdata_part4
select top 50000 *  from posterdata
where PID>(select max(PID) from #temp_part3)
order by PID

sp_makewebtask @outputfile = 'C:\Data\Sitemap\sitemap1.xml',
    @query = 'SELECT ( select ''http://www.artgalore.ca/details.cfm?id=''+ replace(code,'' '',''%20'') as loc, ''monthly'' as changefreq, ''0.5'' as priority  from posterdata_part1 FOR XML PATH(''url''),TYPE)', 
    @templatefile = 'C:\Data\Sitemap\template.tpl'


sp_makewebtask @outputfile = 'C:\Data\Sitemap\sitemap2.xml',
    @query = 'SELECT ( select ''http://www.artgalore.ca/details.cfm?id=''+ replace(code,'' '',''%20'') as loc, ''monthly'' as changefreq, ''0.5'' as priority  from posterdata_part2 FOR XML PATH(''url''),TYPE)', 
    @templatefile = 'C:\Data\Sitemap\template.tpl'
   


sp_makewebtask @outputfile = 'C:\Data\Sitemap\sitemap3.xml',
    @query = 'SELECT ( select ''http://www.artgalore.ca/details.cfm?id=''+ replace(code,'' '',''%20'') as loc, ''monthly'' as changefreq, ''0.5'' as priority  from posterdata_part3 FOR XML PATH(''url''),TYPE)', 
    @templatefile = 'C:\Data\Sitemap\template.tpl'
   


sp_makewebtask @outputfile = 'C:\Data\Sitemap\sitemap4.xml',
    @query = 'SELECT ( select ''http://www.artgalore.ca/details.cfm?id=''+ replace(code,'' '',''%20'') as loc, ''monthly'' as changefreq, ''0.5'' as priority  from posterdata_part4 FOR XML PATH(''url''),TYPE)', 
    @templatefile = 'C:\Data\Sitemap\template.tpl'


sp_makewebtask @outputfile = 'C:\Data\Sitemap\sitemap5.xml',
    @query = 'SELECT ( select distinct ''http://www.artgalore.ca/artlist2.cfm?lname=''+ lname + ''&fname='' + fname as loc, ''monthly'' as changefreq, ''0.5'' as priority  from posterdata FOR XML PATH(''url''),TYPE)', 
    @templatefile = 'C:\Data\Sitemap\template.tpl'