# Image Magick

**URL:** https://forum.kirupa.com/t/image-magick/169919
**Category:** programming
**Created:** [November 21, 2005, 5:49am UTC](https://forum.kirupa.com/t/image-magick/169919 "2005-11-21T05:49:22Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![pbrollwitme](https://avatars.discourse-cdn.com/v4/letter/p/439d5e/32.png) [@pbrollwitme](https://forum.kirupa.com/u/pbrollwitme)
#### Post date: [November 21, 2005, 5:49am UTC](https://forum.kirupa.com/t/image-magick/169919/1 "2005-11-21T05:49:22Z")

</div>

Hello All,  
I posted this question a month or two ago and never got a solution. So i put it away for a while and now i’m back to give it another go. I am trying to make a user profile system in which users can upload pictures of themselves for their profiles. I initially used imageCreateFromJPG but not all jpegs would upload correctly or convert. I was informed that ImageMagick may be the way to go. I have image magik on my server and now i’m trying to use it without success. Below is my code. A file is created with image magick but the file is blank. If i could get the image magick code to work i’m sure the rest would work great. Please help me get this off my “to do” list!! THANK EVERYONE!!

```php
<?php
$db = mysql_connect("localhost", "user","password");
mysql_select_db("members",$db);
$checkuser = mysql_query("SELECT username FROM users WHERE username='$username'"); 
$username_exist = mysql_num_rows( $checkuser );
if($username_exist>0){
   echo "I'm sorry but the username you specified has already 
been taken. Please pick another one.";
   unset($username);
	exit();
}else{
if($uploadedfile_type="image/jpeg" || $uploadedfile_type="image/jpg" ){
$target = "uploads/memberspics/";
$pic = $target . ereg_replace('[^a-z0-9A-Z.]','',$username) . '.' . jpg;
move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $pic);
}
}
fopen("$pic", "a+");
function cmyk2rgb($pic) {
   $mgck_wnd = NewMagickWand();
   MagickReadImage($mgck_wnd, $pic);
   
   $img_colspc = MagickGetImageColorspace($mgck_wnd);
   if ($img_colspc == MW_CMYKColorspace) {
	   echo "$file was in CMYK format<br />";
	   MagickSetImageColorspace($mgck_wnd, MW_RGBColorspace);
   }
   MagickWriteImage($mgck_wnd, str_replace('.', '-rgb.', $pic));
}
$im = imageCreateFromJPG($pic);
imageinterlace($im, 0);
$width = imageSX($im);
$height= imageSY($im);
$n_width =250;  
$n_height = ($height*250)/$width;  
$newimage = ImageCreateTrueColor("$n_width","$n_height");		
ImageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
ImageJpeg($newimage,$pic ,75);
chmod("$pic",0777);
fopen("$pic", "r");
$target_path = "uploads/memberspics/thumbnails/";
$im = imageCreateFromJPEG($pic);
imageinterlace($im, 0);
$width = imageSX($im);
$height= imageSY($im);
$n_width =100;  
$n_height = ($height*100)/$width; 
$newimage = ImageCreateTrueColor("$n_width","$n_height");		
ImageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
ImageJpeg($newimage,$target_path . ereg_replace('[^a-z0-9A-Z.]','',$username) . '.' . jpg,75);
$thumb = $target_path . ereg_replace('[^a-z0-9A-Z.]','',$username) . '.' . jpg;
chmod("$pic",0777);

```
