0

私のサイトで 2 つの機能を組み合わせるには、あなたの助けが必要です。私の目的は、画像をアップロードしてサイズを変更することです。ユーザーの写真をうまく処理する関数が 1 つあり、写真 (リストまたは広告の写真) をアップロードする関数がもう 1 つありますが、この関数は親指の写真を作成しません。アップロードするだけです。私がやりたいのは、関数専用の userpic のようにアップロードしてサイズを変更することです。

あなたが私を助けてくれることを願っています。ユーザー画像に関する機能はこちら(サムサイズリサイズ機能)

public function photo($id = "") {
    $target_path = realpath(APPPATH . '../images/users');
    //echo $target_path;

    if (!is_writable(dirname($target_path))) {
        $this->session->set_flashdata('flash_message', $this->Common_model->flash_message('error', 'Sorry! Destination folder is not writable.'));
        redirect('users/edit', 'refresh');
    } else {
        if (!is_dir(realpath(APPPATH . '../images/users') . '/' . $id)) {
            //echo $this->path.'/'.$id;
            mkdir(realpath(APPPATH . '../images/users') . '/' . $id, 0777, true);
        }

        $target_path = $target_path . '/' . $id . '/userpic.jpg';

        if ($_FILES['upload123']['name'] != '') {
            move_uploaded_file($_FILES['upload123']['tmp_name'], $target_path);

            $thumb1 = realpath(APPPATH . '../images/users') . '/' . $id . '/userpic_thumb.jpg';
            GenerateThumbFile($target_path, $thumb1, 107, 78);

            $thumb2 = realpath(APPPATH . '../images/users') . '/' . $id . '/userpic_profile.jpg';
            GenerateThumbFile($target_path, $thumb2, 209, 209);

            $thumb3 = realpath(APPPATH . '../images/users') . '/' . $id . '/userpic_micro.jpg';
            GenerateThumbFile($target_path, $thumb3, 36, 36);

            $this->session->set_flashdata('flash_message', $this->Common_model->flash_message('success', 'Your profile photo updated successfully.'));
            redirect('users/edit', 'refresh');
        } else {
            $this->session->set_flashdata('flash_message', $this->Common_model->flash_message('error', 'Please browse your profile photo.'));
            redirect('users/edit', 'refresh');
        }
    }
}

そして、これが resize を実装したい関数 id です:

if ($this->input->post()) {
    $listId = $param;
    $images = $this->input->post('image');
    $is_main = $this->input->post('is_main');

    $fimages = $this->Gallery->get_imagesG($listId);
    if ($is_main != '') {
        foreach ($fimages->result() as $row) {
            if ($row->id == $is_main)
                $this->Common_model->updateTableData('list_photo', $row->id, NULL, array("is_featured" => 1));
            else
                $this->Common_model->updateTableData('list_photo', $row->id, NULL, array("is_featured" => 0));
        }
    }

    if (!empty($images)) {
        foreach ($images as $key => $value) {
            $image_name = $this->Gallery->get_imagesG(NULL, array('id' => $value))->row()->name;
            unlink($this->path . '/' . $listId . '/' . $image_name);

            $conditions = array("id" => $value);
            $this->Common_model->deleteTableData('list_photo', $conditions);
        }
    }

    if (isset($_FILES["userfile"]["name"])) {
        $insertData['list_id'] = $listId;

        if (!is_dir($this->path . '/' . $listId)) {
            //echo $this->path.'/'.$id;
            mkdir($this->path . '/' . $listId, 0777, true);
            $insertData['is_featured'] = 1;
        }

        $config = array(
            'allowed_types' => 'jpg|jpeg|gif|png',
            'upload_path' => $this->path . '/' . $listId,
            'encrypt_name' => TRUE,
            'remove_spaces' => TRUE
        );

        //echo $this->path.'/'.$id;
        $this->load->library('upload', $config);
        $data = $this->upload->do_upload();
        if ($data) {
            $this->outputData['file'] = $this->upload->data();
            $insertData['name'] = $this->outputData['file']['file_name'];
            $insertData['created'] = local_to_gmt();

            if ($this->outputData['file']['file_name'] != '')
                $this->Common_model->insertData('list_photo', $insertData);
        }
    }
}
4

2 に答える 2

0

下のコードには、サム ファイルを生成するものは何もありません。

次のようなものが必要です。

$this->thumb_path   = realpath(APPPATH . '../directory/in/codeigniter/site/image/thumb');

次に、$this->upload->data() で画像のアップロードを行った後、親指を生成する必要があります (設定に合わせて調整します)。

$thumb_config = array(
    'source_image' => $data['full_path'],
    'new_image' => $this->thumb_path,
    'maintain_ratio' => true,
    'width' => 200,
    'height' => 200,
    'quality' => '100%'
  );

  $this->load->library('image_lib', $thumb_config);
  $this->image_lib->resize();
于 2012-11-12T20:50:03.410 に答える